Structured error codes: E1000-E5000, no user-facing text in library

Error codes:
 1000-1001: device errors (not found, permission)
 2000-2002: profile errors (unsupported, not found, parse)
 3000-3003: unlock errors (failed, signature, not unlocked, not calibrated)
 4000-4001: SCSI errors (command failed, timeout)
 5000: I/O errors

All errors carry structured data (vendor_id, opcode, etc).
Applications format their own user-facing messages.
Library returns code + data, never English text.
This commit is contained in:
MattJackson
2026-04-06 10:17:43 -07:00
parent 4f0303dcc9
commit cbf510e70e
5 changed files with 129 additions and 51 deletions
+5 -4
View File
@@ -76,7 +76,7 @@ impl SgIoTransport {
let fd = unsafe { libc::open(c_path.as_ptr() as *const libc::c_char, libc::O_RDWR | libc::O_NONBLOCK) };
if fd < 0 {
return Err(Error::DeviceNotFound(device.display().to_string()));
return Err(Error::DeviceNotFound { path: device.display().to_string() });
}
Ok(SgIoTransport { fd })
}
@@ -120,16 +120,17 @@ impl ScsiTransport for SgIoTransport {
};
if ret < 0 {
return Err(Error::Io(std::io::Error::last_os_error()));
return Err(Error::IoError { source: std::io::Error::last_os_error() });
}
let bytes_transferred = (data.len() as i32 - hdr.resid) as usize;
if hdr.status != 0 {
let sense_key = if hdr.sb_len_wr > 2 { sense[2] & 0x0F } else { 0 };
return Err(Error::ScsiError {
cdb: cdb.to_vec(),
opcode: cdb[0],
status: hdr.status,
sense: sense[..hdr.sb_len_wr as usize].to_vec(),
sense_key,
});
}