Commit c51949d2 authored by David Brown's avatar David Brown Committed by David Brown
Browse files

sim: simflash: Convert to thiserror



The thiserror crate seems to be getting more momentum in the community
than failure.  Switch to this for deriving our own error type.

Signed-off-by: default avatarDavid Brown <david.brown@linaro.org>
parent 218aee74
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ authors = ["David Brown <david.brown@linaro.org>"]
edition = "2018"

[dependencies]
failure = "0.1.6"
failure_derive = "0.1.6"
rand = "0.7"
log = "0.4"
thiserror = "1.0"
+7 −13
Original line number Diff line number Diff line
@@ -11,7 +11,6 @@
mod pdump;

use crate::pdump::HexDump;
use failure::Fail;
use log::info;
use rand::{
    self,
@@ -26,25 +25,20 @@ use std::{
    path::Path,
    slice,
};
use thiserror::Error;

pub type Result<T> = std::result::Result<T, FlashError>;

#[derive(Fail, Debug)]
#[derive(Error, Debug)]
pub enum FlashError {
    #[fail(display = "Offset out of bounds: {}", _0)]
    #[error("Offset out of bounds: {0}")]
    OutOfBounds(String),
    #[fail(display = "Invalid write: {}", _0)]
    #[error("Invalid write: {0}")]
    Write(String),
    #[fail(display = "Write failed by chance: {}", _0)]
    #[error("Write failed by chance: {0}")]
    SimulatedFail(String),
    #[fail(display = "{}", _0)]
    Io(#[cause] io::Error),
}

impl From<io::Error> for FlashError {
    fn from(error: io::Error) -> Self {
        FlashError::Io(error)
    }
    #[error("{0}")]
    Io(#[from] io::Error),
}

// Transition from error-chain.