Skip to main content

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("Unsupported operating system for JRE installation")]
16    UnsupportedOS,
17
18    #[error("IO error: {0}")]
19    Io(#[from] std::io::Error),
20
21    #[error("Distribution error: {0}")]
22    Distribution(#[from] DistributionError),
23
24    #[error("Transfer failed: {0}")]
25    Transfer(#[from] lighty_core::errors::DownloadError),
26
27    #[error("Archive error: {0}")]
28    Archive(#[from] lighty_core::errors::ExtractError),
29}
30
31/// Errors related to Java runtime execution
32#[derive(Debug, Error)]
33pub enum JavaRuntimeError {
34    #[error("Java runtime not found at {path:?}")]
35    NotFound { path: std::path::PathBuf },
36
37    #[error("Process exited with non-zero exit code: {code}")]
38    NonZeroExit { code: i32 },
39
40    #[error("Failed to capture process I/O - stdout/stderr not configured")]
41    IoCaptureFailure,
42
43    #[error("Process spawn error: {0}")]
44    Spawn(#[from] std::io::Error),
45
46    #[error("Process terminated by signal")]
47    SignalTerminated,
48}
49
50/// Errors related to Java distribution management
51#[derive(Debug, Error)]
52pub enum DistributionError {
53    #[error("Unsupported Java version {version} for distribution {distribution}")]
54    UnsupportedVersion { version: u8, distribution: &'static str },
55
56    #[error("API error for {distribution}: {error}")]
57    ApiError { distribution: &'static str, error: String },
58
59    #[error("JSON parse error for {distribution}: {error}")]
60    JsonParseError { distribution: &'static str, error: String },
61
62    #[error("No packages found for {distribution}")]
63    NoPackagesFound { distribution: &'static str },
64
65    #[error("System error: {0}")]
66    System(#[from] lighty_core::SystemError),
67}
68
69/// Type alias for JRE operations results
70pub type JreResult<T> = Result<T, JreError>;
71
72/// Type alias for Java runtime operations results
73pub type JavaRuntimeResult<T> = Result<T, JavaRuntimeError>;
74
75/// Type alias for Java distribution operations results
76pub type DistributionResult<T> = Result<T, DistributionError>;