mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
block: qcow: Switch parse_qcow and BackingFile::new to BlockResult
Switch parse_qcow and BackingFile::new from qcow::Result to BlockResult. Every early return site now produces an explicit BlockError with the appropriate kind. Remaining internal calls to functions still on qcow::Result rely on the From scaffolding and will be converted in subsequent commits. Two helpers are added to BlockError. with_kind replaces the classification on an existing error, used in QcowDiskSync::new to avoid double wrapping when the caller needs a different kind. into_source consumes the error and returns the boxed source, used at the recursive BackingFile open to extract the qcow::Error for BackingFileOpen without letting qcow::Error hold a BlockError. The qcow_sync boundary is simplified to a single closure that operates on the BlockError already returned by parse_qcow. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
This commit is contained in:
committed by
Rob Bradford
parent
c4a5c7f843
commit
be9ef116aa
@@ -167,6 +167,12 @@ impl BlockError {
|
||||
self
|
||||
}
|
||||
|
||||
/// Replace the error classification (builder-style).
|
||||
pub fn with_kind(mut self, kind: BlockErrorKind) -> Self {
|
||||
self.kind = kind;
|
||||
self
|
||||
}
|
||||
|
||||
/// Shorthand: attach an operation name.
|
||||
pub fn with_op(mut self, op: ErrorOp) -> Self {
|
||||
self.ctx.get_or_insert_with(ErrorContext::default).op = Some(op);
|
||||
@@ -204,6 +210,11 @@ impl BlockError {
|
||||
pub fn downcast_ref<T: StdError + 'static>(&self) -> Option<&T> {
|
||||
self.source.as_ref()?.downcast_ref::<T>()
|
||||
}
|
||||
|
||||
/// Consume the error and return the boxed source, if any.
|
||||
pub fn into_source(self) -> Option<Box<dyn StdError + Send + Sync + 'static>> {
|
||||
self.source
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for BlockError {
|
||||
|
||||
Reference in New Issue
Block a user