Errors
mudrit_keystore::Error and mudrit_pdfsign::Error — every variant, From conversions, and the non_exhaustive matching pattern
Mudrit has two error types, one per layer: mudrit_keystore::Error for key
discovery / unlocking / signing at the backend level, and
mudrit_pdfsign::Error for everything above it — PDF parsing, placement,
encryption, and the signing pipeline itself. Both are #[derive(Debug, Clone)] and
#[non_exhaustive].
#[non_exhaustive] — always add a wildcard arm
New variants can be added in a minor release without it being a breaking change, but that means your
match must include a _ => arm or it won't compile against a newer Mudrit. Match on the
variants you handle specifically and fall through to a generic message for the rest.
mudrit_keystore::Error
Prop
Type
From conversions — these let you use ? from lower-level code without a manual .map_err:
Prop
Type
std::error::Error::source() returns Some(&**s) only for Io { source: Some(s), .. } — every other
variant has no underlying source (the String already carries what happened).
use mudrit::mudrit_keystore::Error;
match mgr.unlock(&token, serial, Some(pin)) {
Ok(signer) => { /* ... */ }
Err(Error::WrongPin { final_try: true, .. }) => eprintln!("last attempt — be careful!"),
Err(Error::WrongPin { count_low: true, .. }) => eprintln!("PIN wrong, only a few tries left"),
Err(Error::PinLocked) => eprintln!("PIN locked — unlock the token on-device"),
Err(Error::Cancelled) => { /* user backed out, not an error */ }
Err(e) => eprintln!("could not unlock: {e}"),
}mudrit_pdfsign::Error
Prop
Type
From conversions:
Prop
Type
source() returns Some(e) only for Keystore(e) — that's the one variant with a further
std::error::Error underneath it.
use mudrit_pdfsign::prelude::*;
match sign_pdf(&pdf, signer.as_ref(), &cfg) {
Ok(signed) => std::fs::write("out.pdf", signed)?,
Err(Error::Keystore(e)) => eprintln!("signer problem: {e}"),
Err(Error::Network(msg)) => eprintln!("timestamp/OCSP fetch failed: {msg}"),
Err(e) => eprintln!("signing failed: {e}"),
}