Skip to main content

stylus_trace_core/utils/
error.rs

1//! Error types for the entire application.
2//!
3//! We use `thiserror` for library-style errors with custom types,
4//! and `anyhow` for application-level error propagation in main.rs and commands.
5
6use thiserror::Error;
7
8/// Errors that can occur during RPC communication
9#[derive(Error, Debug)]
10pub enum RpcError {
11    #[error("HTTP request failed: {0}")]
12    RequestFailed(#[from] reqwest::Error),
13
14    #[error("Invalid RPC response: {0}")]
15    InvalidResponse(String),
16
17    #[error("Transaction not found: {0}")]
18    TransactionNotFound(String),
19
20    #[error("Tracer not supported by this RPC endpoint")]
21    TracerNotSupported,
22}
23
24/// Errors that can occur during trace parsing
25#[derive(Error, Debug)]
26pub enum ParseError {
27    #[error("JSON deserialization failed: {0}")]
28    JsonError(#[from] serde_json::Error),
29
30    #[error("Invalid trace format: {0}")]
31    InvalidFormat(String),
32    /*
33        #[error("Unsupported schema version: {0}")]
34        UnsupportedVersion(String),
35
36        #[error("Missing required field: {0}")]
37        MissingField(String),
38    */
39}
40
41/// Errors that can occur during flamegraph generation
42#[derive(Error, Debug)]
43pub enum FlamegraphError {
44    /*
45        #[error("Failed to generate flamegraph: {0}")]
46        GenerationFailed(String),
47    */
48    #[error("Empty stack data")]
49    EmptyStacks,
50
51    #[error("IO error: {0}")]
52    IoError(#[from] std::io::Error),
53}
54
55/// Errors that can occur during file output
56#[derive(Error, Debug)]
57pub enum OutputError {
58    #[error("Failed to write file: {0}")]
59    WriteFailed(#[from] std::io::Error),
60
61    #[error("Failed to serialize JSON: {0}")]
62    SerializationFailed(#[from] serde_json::Error),
63
64    #[error("Invalid output path: {0}")]
65    InvalidPath(String),
66}
67
68/// Errors that can occur during profile comparison (diff)
69#[derive(Error, Debug)]
70pub enum DiffError {
71    #[error("Incompatible schema versions: baseline={0}, target={1}")]
72    IncompatibleVersions(String, String),
73
74    #[error("Failed to read profile: {0}")]
75    ReadFailed(#[from] OutputError),
76
77    #[error("Invalid threshold configuration: {0}")]
78    InvalidThresholds(String),
79
80    #[error("Threshold TOML parse error: {0}")]
81    ThresholdParseFailed(#[from] toml::de::Error),
82
83    #[error("IO error: {0}")]
84    IoError(#[from] std::io::Error),
85}