Skip to content

Commit ea3a4e3

Browse files
committed
nvme: Implement From<DekuError> for AdminIoCqeGenericCommandStatus
This will help tidy up the error handling using .map_err(). Signed-off-by: Andrew Jeffery <andrew@codeconstruct.com.au>
1 parent 7b8a695 commit ea3a4e3

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/nvme.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
pub mod mi;
66

77
use deku::ctx::Endian;
8-
use deku::{DekuRead, DekuWrite, deku_derive};
8+
use deku::{DekuError, DekuRead, DekuWrite, deku_derive};
99
use flagset::flags;
10+
use log::debug;
1011

1112
use crate::wire::WireFlagSet;
1213
use crate::wire::WireString;
@@ -106,9 +107,17 @@ unsafe impl Discriminant<u8> for AdminIoCqeStatusType {}
106107
enum AdminIoCqeGenericCommandStatus {
107108
SuccessfulCompletion = 0x00,
108109
InvalidFieldInCommand = 0x02,
110+
InternalError = 0x06,
109111
}
110112
unsafe impl Discriminant<u8> for AdminIoCqeGenericCommandStatus {}
111113

114+
impl From<DekuError> for AdminIoCqeGenericCommandStatus {
115+
fn from(err: DekuError) -> Self {
116+
debug!("Codec operation failed: {err}");
117+
Self::InternalError
118+
}
119+
}
120+
112121
// Base v2.1, 4.6.1, Figure 137
113122
// TODO: Unify with ControllerListResponse
114123
#[derive(Debug, DekuRead, Eq, PartialEq)]

0 commit comments

Comments
 (0)