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
+20 -6
View File
@@ -36,12 +36,18 @@ impl DriveSession {
// Match drive to a profile by INQUIRY fields
let profile = profile::find_by_drive_id(&profiles, &drive_id)
.cloned()
.ok_or_else(|| Error::UnsupportedDrive(format!("{}", drive_id)))?;
.ok_or_else(|| Error::UnsupportedDrive {
vendor_id: drive_id.vendor_id.trim().to_string(),
product_id: drive_id.product_id.trim().to_string(),
product_revision: drive_id.product_revision.trim().to_string(),
})?;
if !profile.supported {
return Err(Error::UnsupportedDrive(format!(
"{} — status: {:?}", drive_id, profile.status
)));
return Err(Error::UnsupportedDrive {
vendor_id: drive_id.vendor_id.trim().to_string(),
product_id: drive_id.product_id.trim().to_string(),
product_revision: drive_id.product_revision.trim().to_string(),
});
}
let platform: Box<dyn Platform> = match profile.platform {
@@ -49,7 +55,11 @@ impl DriveSession {
Box::new(Mt1959::new(profile.clone()))
}
PlatformType::Pioneer => {
return Err(Error::UnsupportedDrive("Pioneer not yet implemented".into()));
return Err(Error::UnsupportedDrive {
vendor_id: drive_id.vendor_id.trim().to_string(),
product_id: drive_id.product_id.trim().to_string(),
product_revision: "Pioneer not yet implemented".to_string(),
});
}
};
@@ -71,7 +81,11 @@ impl DriveSession {
Box::new(Mt1959::new(profile.clone()))
}
PlatformType::Pioneer => {
return Err(Error::UnsupportedDrive("Pioneer not yet implemented".into()));
return Err(Error::UnsupportedDrive {
vendor_id: drive_id.vendor_id.trim().to_string(),
product_id: drive_id.product_id.trim().to_string(),
product_revision: "Pioneer not yet implemented".to_string(),
});
}
};