1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#[cfg(feature = "bridge")]
use polars::error::PolarsError;
use thiserror::Error;
/// The main error type for the charton crate.
///
/// This enum encompasses all possible error conditions that can occur within
/// the charton library. It uses the `thiserror` crate to provide automatic
/// implementation of `std::error::Error` and `Display` traits, making error
/// handling consistent and ergonomic.
///
/// Most variants wrap a `String` message that describes the specific error,
/// while some variants automatically convert from underlying library errors
/// using the `#[from]` attribute.
#[derive(Error, Debug)]
pub enum ChartonError {
/// Error related to data handling or processing.
/// Used for inconsistent lengths, empty datasets, or invalid types.
#[error("Data error: {0}")]
Data(String),
/// Error related to mark definitions or configurations.
#[error("Mark error: {0}")]
Mark(String),
/// Error related to encoding specifications.
#[error("Encoding error: {0}")]
Encoding(String),
/// Formatting error during string formatting operations.
#[error("formatting error: {0}")]
Fmt(#[from] std::fmt::Error),
/// Error related to scale definitions or operations.
#[error("Scale error: {0}")]
Scale(String),
/// Error during rendering operations.
#[error("Render error: {0}")]
Render(String),
/// I/O error from standard library operations.
#[error("io error: {0}")]
Io(#[from] std::io::Error),
/// Error related to SVG processing or usvg operations.
#[error("svg/usvg error")]
Svg,
/// Error related to executable path validation.
#[error("Executable path error: {0}")]
ExecutablePath(String),
/// Error for unimplemented features.
#[error("Unimplemented feature: {0}")]
Unimplemented(String),
/// Error for internal logic errors.
#[error("Internal error: {0}")]
Internal(String),
/// Error from the Polars library.
///
/// This variant automatically converts `PolarsError` instances into `ChartonError`.
/// The `?` operator will automatically perform this conversion when working with
/// Polars operations that can fail.
#[cfg(feature = "bridge")]
#[error("polars error: {0}")]
Polars(#[from] PolarsError),
}