Display inner PC/SC errors (#420)

This commit is contained in:
william light
2022-10-31 23:00:21 +01:00
committed by GitHub
parent c89cc5acd0
commit bbb186f95e
+24 -18
View File
@@ -121,31 +121,37 @@ impl Error {
} }
/// Error message /// Error message
pub fn msg(self) -> &'static str { pub fn msg(self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self { match self {
Error::AlgorithmError => "algorithm error", Error::AlgorithmError => f.write_str("algorithm error"),
Error::AppletError => "applet error", Error::AppletError => f.write_str("applet error"),
Error::ArgumentError => "argument error", Error::ArgumentError => f.write_str("argument error"),
Error::AuthenticationError => "authentication error", Error::AuthenticationError => f.write_str("authentication error"),
Error::GenericError => "generic error", Error::GenericError => f.write_str("generic error"),
Error::InvalidObject => "invalid object", Error::InvalidObject => f.write_str("invalid object"),
Error::KeyError => "key error", Error::KeyError => f.write_str("key error"),
Error::MemoryError => "memory error", Error::MemoryError => f.write_str("memory error"),
Error::NotSupported => "not supported", Error::NotSupported => f.write_str("not supported"),
Error::NotFound => "not found", Error::NotFound => f.write_str("not found"),
Error::ParseError => "parse error", Error::ParseError => f.write_str("parse error"),
Error::PcscError { .. } => "PC/SC error",
Error::PinLocked => "PIN locked", Error::PcscError {
Error::RangeError => "range error", inner: Some(pcsc_error),
Error::SizeError => "size error", } => f.write_fmt(format_args!("PC/SC error: {}", pcsc_error)),
Error::WrongPin { .. } => "wrong pin",
Error::PcscError { .. } => f.write_str("PC/SC error"),
Error::PinLocked => f.write_str("PIN locked"),
Error::RangeError => f.write_str("range error"),
Error::SizeError => f.write_str("size error"),
Error::WrongPin { .. } => f.write_str("wrong pin"),
} }
} }
} }
impl Display for Error { impl Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.msg()) self.msg(f)
} }
} }