lighty_java/
errors.rs

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