Skip to main content

arborist_cli/
error.rs

1use std::process::ExitCode;
2
3#[derive(Debug, thiserror::Error)]
4pub enum ArboristError {
5    #[error("{0}")]
6    Io(#[from] std::io::Error),
7
8    #[error("analysis error: {0}")]
9    Analysis(String),
10
11    #[error("--language is required when reading from stdin")]
12    NoLanguage,
13
14    #[error("invalid argument: {0}")]
15    InvalidArgument(String),
16}
17
18pub struct ExitReport {
19    pub threshold_exceeded: bool,
20    pub had_errors: bool,
21}
22
23impl ExitReport {
24    pub fn exit_code(&self) -> ExitCode {
25        if self.had_errors {
26            ExitCode::from(2)
27        } else if self.threshold_exceeded {
28            ExitCode::from(1)
29        } else {
30            ExitCode::SUCCESS
31        }
32    }
33}