lighty_java/
errors.rs

1use thiserror::Error;
2
3/// Errors related to Java Runtime Environment (JRE) operations
4#[derive(Debug, Error)]
5pub enum JreError {
6    #[error("JRE not found at {path}")]
7    NotFound { path: String },
8
9    #[error("Invalid JRE structure in directory")]
10    InvalidStructure,
11
12    #[error("Download failed: {0}")]
13    Download(String),
14
15    #[error("Unsupported operating system for JRE installation")]
16    UnsupportedOS,
17
18    #[error("IO error: {0}")]
19    Io(#[from] std::io::Error),
20
21    #[error("Extraction failed: {0}")]
22    Extraction(String),
23}
24
25/// Errors related to Java runtime execution
26#[derive(Debug, Error)]
27pub enum JavaRuntimeError {
28    #[error("Java runtime not found at {path}")]
29    NotFound { path: String },
30
31    #[error("Process exited with non-zero exit code: {code}")]
32    NonZeroExit { code: i32 },
33
34    #[error("Failed to capture process I/O - stdout/stderr not configured")]
35    IoCaptureFailure,
36
37    #[error("Process spawn error: {0}")]
38    Spawn(#[from] std::io::Error),
39
40    #[error("Process terminated by signal")]
41    SignalTerminated,
42}
43
44/// Errors related to Java distribution management
45#[derive(Debug, Error)]
46pub enum DistributionError {
47    #[error("Unsupported Java version {version} for distribution {distribution}")]
48    UnsupportedVersion { version: u32, distribution: String },
49
50    #[error("System error: {0}")]
51    System(#[from] lighty_core::SystemError),
52}
53
54/// Type alias for JRE operations results
55pub type JreResult<T> = Result<T, JreError>;
56
57/// Type alias for Java runtime operations results
58pub type JavaRuntimeResult<T> = Result<T, JavaRuntimeError>;
59
60/// Type alias for Java distribution operations results
61pub type DistributionResult<T> = Result<T, DistributionError>;