Skip to main content

joule_profiler_core/profiler/
error.rs

1use crate::orchestrator::error::OrchestratorError;
2use crate::source::error::MetricSourceError;
3use thiserror::Error;
4
5/// Top-level error type for `JouleProfiler`.
6///
7/// Represents all possible errors that can occur during profiler execution,
8/// from initialization and orchestration to source errors and aggregation.
9#[derive(Debug, Error)]
10pub enum JouleProfilerError {
11    /// The profiled command failed during execution.
12    #[error("Failed to execute command: {0}")]
13    CommandExecutionFailed(String),
14
15    /// The profiled command binary was not found on the system.
16    #[error("Command not found: {0}")]
17    CommandNotFound(String),
18
19    #[error("The provided command is empty.")]
20    EmptyCommand,
21
22    /// The output file could not be created at the given path.
23    #[error("Failed to create output file: {0}")]
24    OutputFileCreationFailed(String),
25
26    /// The provided token pattern is not a valid regular expression.
27    #[error("Invalid regex pattern: {0}")]
28    InvalidPattern(#[from] regex::Error),
29
30    /// Failed to capture the profiled command's stdout.
31    #[error("Stdout capture failed")]
32    StdOutCaptureFail,
33
34    /// Failed to retrieve `SUDO_USER` environment variable.
35    #[error(
36        "Cannot retrieve SUDO_USER environment variable, please retry without root privileges or use \"--use-root\" CLI argument."
37    )]
38    CannotRetrieveSudoUser,
39
40    /// The environment variable exists but is not parsable into the wanted format.
41    #[error("Unable to parse {0} environment variable.")]
42    CannotParseEnvVariable(String),
43
44    /// Unable to retrieve the current effective user id by it's name with the `getpwnam` libc function.
45    #[error("Unable to retrieve current user id by it's name.")]
46    CannotRetrieveCurrentUserId,
47
48    /// Cannot convert string to a known metric unit.
49    #[error("Invalid metric unit: {0}")]
50    InvalidUnit(String),
51
52    /// Generic I/O error.
53    #[error("I/O error")]
54    IoError(
55        #[from]
56        #[source]
57        std::io::Error,
58    ),
59
60    /// Returned when there's no metric sources configured to profile the program with.
61    #[error("No metric sources configured.")]
62    NoSourceConfigured,
63
64    /// A process control operation (e.g. kill, wait) failed.
65    #[error("Process control failed: {0}")]
66    ProcessControlFailed(String),
67
68    /// Failed to spawn the stdout reader thread.
69    #[error("Failed to spawn stdout reader thread: {0}")]
70    ReaderThreadSpawnFailed(String),
71
72    /// The stdout reader thread panicked before completing.
73    #[error("Stdout reader thread panicked")]
74    ReaderThreadPanicked,
75
76    /// Error propagated from a metric source.
77    #[error("Metric source error.")]
78    MetricSourceError(#[from] MetricSourceError),
79
80    /// Error propagated from the source orchestrator.
81    #[error("Orchestrator error.")]
82    OrchestratorError(#[from] OrchestratorError),
83}