apple_clis/
error.rs

1use camino::Utf8PathBuf;
2
3#[derive(thiserror::Error, Debug)]
4pub enum Error {
5	#[error("Command exited with an error: {0}")]
6	ExecuteErrored(#[from] bossy::Error),
7
8	/// Gained by calling an `success` method on a command output
9	#[error("The output of a command did not succeed as expected")]
10	OutputErrored {
11		debug_msg: String,
12		help_hint: Option<String>,
13	},
14
15	/// TODO: propagate more information
16	#[error("Calling `--version` failed")]
17	VersionCheckFailed(#[source] Option<bossy::Error>),
18
19	#[error("Error parsing command JSON output: {0}")]
20	ParseJson(#[from] serde_json::Error),
21
22	/// Used for [nom] parsing errors
23	#[error("Failed to parse {}: {:?}", name, err)]
24	NomParsingFailed {
25		/// What was being parsed
26		name: String,
27		#[source]
28		err: nom::Err<nom::error::Error<String>>,
29	},
30
31	/// Used for [nom] parsing errors
32	#[error(
33		"The parsed string was not completely consumed, with {:?} left from {:?}. Parsed: {:?}",
34		input,
35		remaining,
36		parsed_debug
37	)]
38	ParsingRemainingNotEmpty {
39		input: String,
40		remaining: String,
41		/// [Debug] representation of parsed value
42		parsed_debug: String,
43	},
44
45	/// [crate::open::well_known::WellKnown] was unable to locate the path on disk
46	#[error(
47		"The hard coded path {:?} was not found ({:?}: {err:?})",
48		hard_coded_path,
49		err
50	)]
51	WellKnownPathNotFound {
52		hard_coded_path: Utf8PathBuf,
53		err: Option<std::io::Error>,
54	},
55
56	#[error("Path does not exist: {path} ({err:?}: {err:?})")]
57	PathDoesNotExist {
58		path: Utf8PathBuf,
59		err: Option<std::io::Error>,
60	},
61
62	#[error("Error converting path to UTF-8: {0}")]
63	PathNotUtf8(#[from] camino::FromPathBufError),
64
65	#[error("Error parsing X509 cert: {0}")]
66	X509ParseFailed(#[from] openssl::error::ErrorStack),
67
68	#[error(
69		"Error trying to parse the `codesign` status of a .app: Missing property {}",
70		missing_key
71	)]
72	SigningPropertyNotFound { missing_key: String },
73
74	#[error("Error parsing date: {0}")]
75	ParseDateError(#[from] time::error::Parse),
76
77	#[error("Error find with `which`: {0}")]
78	CannotFindWithWhich(#[from] which::Error),
79
80	#[error("Error finding .app directory: {err:?} at {path}")]
81	AppDirectoryConstructorError {
82		path: Utf8PathBuf,
83		err: Option<std::io::Error>,
84	},
85
86	#[error("Couldn't locate the stderr output stream even though the command errored: {err}")]
87	CannotLocateStderrStream {
88		err: bossy::Error,
89	}
90}
91
92impl Error {
93	pub(crate) fn output_errored(debug_msg: impl std::fmt::Debug) -> Self {
94		Self::OutputErrored {
95			debug_msg: format!("{:#?}", debug_msg),
96			help_hint: None,
97		}
98	}
99
100	pub(crate) fn output_errored_with_hint(debug_msg: impl std::fmt::Debug, help_hint: impl ToString) -> Self {
101		Self::OutputErrored {
102			debug_msg: format!("{:#?}", debug_msg),
103			help_hint: Some(help_hint.to_string()),
104		}
105	}
106}
107
108pub type Result<T> = std::result::Result<T, crate::error::Error>;