Replace unwrap panics with proper error propagation#10
Open
kirgene wants to merge 2 commits intoublk-org:mainfrom
Open
Replace unwrap panics with proper error propagation#10kirgene wants to merge 2 commits intoublk-org:mainfrom
kirgene wants to merge 2 commits intoublk-org:mainfrom
Conversation
All IO backend new() functions (sync, tokio, uring) now return Qcow2Result instead of panicking on file open failures. Both setup macros propagate these errors with ?. check_cluster now returns Err on non-allocated clusters instead of silently printing a warning and returning Ok. main() exits with code 1 on error instead of panicking via unwrap.
Collaborator
|
Hello, The build is failed: Thanks, |
Author
|
Fixed, added unwrap() to the test. |
e2a2196 to
f5ccaa6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I'm using qcow2-rs as a library via rublk to expose qcow2 images as ublk block devices. When rublk hits a corrupt or malformed image, the unwrap() in the IO backend's new() panics and kills the daemon. Since the kernel-side ublk device is already registered at that point, the orphaned device causes unkillable D-state processes — only a reboot fixes it.
This patch replaces unwrap() with proper error propagation across all IO backends and the setup macros, so callers get a clean error instead of a process crash.
Also fixes
rqcow2 check— it was printing "non-allocated cluster" warnings but still returning exit 0, which made it useless for scripted pre-validation. Now it returns exit 1 on integrity errors.Changes:
Qcow2IoSync::new(),Qcow2IoTokio::new(),Qcow2IoUring::new()returnQcow2Resultinstead of panicking on file openqcow2_setup_dev_fn_sync!andqcow2_setup_dev_fn!macros propagate the error with?check_cluster()returnsErrwhen a cluster is non-allocated (wasOk(()))main()prints the error and exits 1 instead of panickingTested against a mix of valid and corrupt qcow2 images.