#[derive(thiserror::Error, Debug, Clone)]
pub enum Error {
#[error("No acceptable signatures found")]
NoSignature,
#[error("Asymmetric algorithm unsupported")]
UnsupportedAsymmetricAlgo,
#[error("Certificate not encryption-capable")]
CertCannotEncrypt,
#[error("Missing required argument")]
MissingArg,
#[error("Incomplete verification instructions")]
IncompleteVerification,
#[error("Unable to decrypt")]
CannotDecrypt,
#[error("Non-UTF-8 or otherwise unreliable password")]
PasswordNotHumanReadable,
#[error("Unsupported option")]
UnsupportedOption,
#[error("Invalid data type")]
BadData,
#[error("Non-text input where text expected")]
ExpectedText,
#[error("Output file already exists")]
OutputExists,
#[error("Input file does not exist")]
MissingInput,
#[error("A KEY input is protected with a password")]
KeyIsProtected,
#[error("Unsupported subcommand")]
UnsupportedSubcommand,
#[error("An indirect parameter is a special designator with unknown prefix")]
UnsupportedSpecialPrefix,
#[error("A indirect input parameter is a special designator matches file")]
AmbiguousInput,
}
impl From<Error> for i32 {
fn from(e: Error) -> Self {
use Error::*;
match e {
NoSignature => 3,
UnsupportedAsymmetricAlgo => 13,
CertCannotEncrypt => 17,
MissingArg => 19,
IncompleteVerification => 23,
CannotDecrypt => 29,
PasswordNotHumanReadable => 31,
UnsupportedOption => 37,
BadData => 41,
ExpectedText => 53,
OutputExists => 59,
MissingInput => 61,
KeyIsProtected => 67,
UnsupportedSubcommand => 69,
UnsupportedSpecialPrefix => 71,
AmbiguousInput => 73,
}
}
}
pub fn print_error_chain(err: &anyhow::Error) {
eprintln!(" {}", err);
err.chain().skip(1).for_each(|cause| eprintln!(" because: {}", cause));
}