Debian Codegraph @

src/collection/error.rs

raw symbols SCIP
1 use anyhow::anyhow;
2
3 /// An error to do with data collection.
4 #[derive(Debug)]
5 pub enum CollectionError {
6 /// A general error to propagate back up. A wrapper around
7 /// [`anyhow::Error`].
8 General(anyhow::Error),
9
10 /// The collection is unsupported.
11 #[allow(
12 dead_code,
13 reason = "this is not used if everything is supported for the platform"
14 )]
15 Unsupported,
16 }
17
18 impl std::fmt::Display for CollectionError {
19 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
20 match self {
21 CollectionError::General(err) => err.fmt(f),
22 CollectionError::Unsupported => {
23 write!(
24 f,
25 "bottom does not support this type of data collection for this platform."
26 )
27 }
28 }
29 }
30 }
31
32 impl std::error::Error for CollectionError {}
33
34 /// A [`Result`] with the error type being a [`DataCollectionError`].
35 pub(crate) type CollectionResult<T> = Result<T, CollectionError>;
36
37 impl From<std::io::Error> for CollectionError {
38 fn from(err: std::io::Error) -> Self {
39 Self::General(err.into())
40 }
41 }
42
43 impl From<&'static str> for CollectionError {
44 fn from(msg: &'static str) -> Self {
45 Self::General(anyhow!(msg))
46 }
47 }