Skip to content

[Cleanup] Audit: Replace panics (unwrap/expect) with Result in libwayshot #291

@0xsamalt

Description

@0xsamalt

Libwayshot currently has certain instances of unwrap() and I think replacing it to Result is good for the stability of library and they can cause host application to panic at runtime.

I am proposing to replace all the instances of unwrap() to Result with proper error msgs.

I have analyzed and found the following instances:

src/lib.rs:            bo.fd_for_plane(0).unwrap(),
src/dispatch.rs:                let format = state.formats.first_mut().unwrap();
src/dispatch.rs:                let set_format = state.formats.first_mut().unwrap();
src/dispatch.rs:                let device = u64::from_le_bytes(device.try_into().unwrap());
src/dispatch.rs:        Card(options.open(path).unwrap())

Proposed Implementation:
Convert affected functions to return Result<T, Error> with proper error messages indicating the failure reason.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions