misc: devices: streamline #[source] and Error
This streamlines the code base to follow best practices for error handling in Rust: Each error struct implements std::error::Error (most due via thiserror::Error derive macro) and sets its source accordingly. This allows future work that nicely prints the error chains, for example. So far, the convention is that each error prints its sub error as part of its Display::fmt() impl. Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de> On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
parent
01761c2596
commit
93b599e59e
4 changed files with 11 additions and 11 deletions
|
|
@ -18,22 +18,22 @@ pub enum Error {
|
|||
InvalidDeliveryMode,
|
||||
/// Failed creating the interrupt source group.
|
||||
#[error("Failed creating the interrupt source group: {0}")]
|
||||
CreateInterruptSourceGroup(io::Error),
|
||||
CreateInterruptSourceGroup(#[source] io::Error),
|
||||
/// Failed triggering the interrupt.
|
||||
#[error("Failed triggering the interrupt: {0}")]
|
||||
TriggerInterrupt(io::Error),
|
||||
TriggerInterrupt(#[source] io::Error),
|
||||
/// Failed masking the interrupt.
|
||||
#[error("Failed masking the interrupt: {0}")]
|
||||
MaskInterrupt(io::Error),
|
||||
MaskInterrupt(#[source] io::Error),
|
||||
/// Failed unmasking the interrupt.
|
||||
#[error("Failed unmasking the interrupt: {0}")]
|
||||
UnmaskInterrupt(io::Error),
|
||||
UnmaskInterrupt(#[source] io::Error),
|
||||
/// Failed updating the interrupt.
|
||||
#[error("Failed updating the interrupt: {0}")]
|
||||
UpdateInterrupt(io::Error),
|
||||
UpdateInterrupt(#[source] io::Error),
|
||||
/// Failed enabling the interrupt.
|
||||
#[error("Failed enabling the interrupt: {0}")]
|
||||
EnableInterrupt(io::Error),
|
||||
EnableInterrupt(#[source] io::Error),
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
/// Failed creating GIC device.
|
||||
#[error("Failed creating GIC device: {0}")]
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub enum Error {
|
|||
#[error("GPIO interrupt disabled by guest driver.")]
|
||||
GpioInterruptDisabled,
|
||||
#[error("Could not trigger GPIO interrupt: {0}.")]
|
||||
GpioInterruptFailure(io::Error),
|
||||
GpioInterruptFailure(#[source] io::Error),
|
||||
#[error("Invalid GPIO Input key triggered: {0}.")]
|
||||
GpioTriggerKeyFailure(u32),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ pub enum Error {
|
|||
#[error("Bad Write Offset: {0}")]
|
||||
BadWriteOffset(u64),
|
||||
#[error("Failed to trigger interrupt: {0}")]
|
||||
InterruptFailure(io::Error),
|
||||
InterruptFailure(#[source] io::Error),
|
||||
}
|
||||
|
||||
type Result<T> = result::Result<T, Error>;
|
||||
|
|
|
|||
|
|
@ -54,11 +54,11 @@ pub enum Error {
|
|||
#[error("pl011: DMA not implemented.")]
|
||||
DmaNotImplemented,
|
||||
#[error("Failed to trigger interrupt: {0}")]
|
||||
InterruptFailure(io::Error),
|
||||
InterruptFailure(#[source] io::Error),
|
||||
#[error("Failed to write: {0}")]
|
||||
WriteAllFailure(io::Error),
|
||||
WriteAllFailure(#[source] io::Error),
|
||||
#[error("Failed to flush: {0}")]
|
||||
FlushFailure(io::Error),
|
||||
FlushFailure(#[source] io::Error),
|
||||
}
|
||||
|
||||
type Result<T> = result::Result<T, Error>;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue