Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Study a better way to unwrap errors #21

Open
Zildj1an opened this issue Nov 21, 2022 · 2 comments
Open

Study a better way to unwrap errors #21

Zildj1an opened this issue Nov 21, 2022 · 2 comments
Labels
question Further information is requested

Comments

@Zildj1an
Copy link
Contributor

Something we can have like unwrap, that instead of panic will call vc_terminate_xxxx. Consider this code:

    let init_frame: PhysFrame = match mem_allocate_frames(init_count) {
        Some(f) => f,
        None => vc_terminate_svsm_enomem(),
    };

from something generic resembling:

pub trait CustomUnwrap<T> {
    fn unwrap_svsm_enomem(self) -> T;
}

impl CustomUnwrap<T> for Option<T> {
    fn unwrap_svsm_enomem(self) -> T {
        match self {
            Some(value) => value,
            None => vc_terminate_svsm_enomem(),
        }
    }
}
@Zildj1an Zildj1an added the question Further information is requested label Nov 21, 2022
@arkivm
Copy link
Contributor

arkivm commented Nov 21, 2022

#20 (comment)
Moving the discussion here.

@arkivm is it possible to do this in a generic way, for every Option and Result? Something like (not sure this is valid syntax):

Yeah @dubek. Something like this: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=f02235e475a51d042e8649254455c75e

@dubek
Copy link
Contributor

dubek commented Nov 21, 2022

Another more general question is whether we want to directly terminate, or propagate errors up (let's say all the way up to svsm_request_loop()) and there call the relevant vc_terminate_xxxx if needed. Inside the function we'll use a lot of ? operators to detect Err and None etc and return.

Ideally this will allow unit-testing some parts, but not sure it's worth the (big) effort.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants