Skip to main content

nix_env_manager/
error.rs

1//! Error types for nix-env-manager
2
3use thiserror::Error;
4
5/// Errors that can occur in the Nix environment manager
6#[derive(Error, Debug)]
7pub enum NixError {
8    /// Nix command not found
9    #[error("Nix is not installed or not in PATH")]
10    NixNotFound,
11
12    /// Nix command execution failed
13    #[error("Nix command failed: {0}")]
14    NixCommandFailed(String),
15
16    /// Flake not found
17    #[error("Flake not found at path: {0}")]
18    FlakeNotFound(String),
19
20    /// Invalid flake.lock format
21    #[error("Invalid flake.lock format: {0}")]
22    InvalidFlakeLock(String),
23
24    /// Attic not configured
25    #[error("Attic is not configured")]
26    AtticNotConfigured,
27
28    /// Attic command failed
29    #[error("Attic command failed: {0}")]
30    AtticCommandFailed(String),
31
32    /// Environment not found in cache
33    #[error("Environment not found in cache: {0}")]
34    EnvironmentNotCached(String),
35
36    /// IO error
37    #[error("IO error: {0}")]
38    Io(#[from] std::io::Error),
39
40    /// JSON parsing error
41    #[error("JSON parsing error: {0}")]
42    Json(#[from] serde_json::Error),
43
44    /// HTTP error (for Attic API)
45    #[error("HTTP error: {0}")]
46    Http(String),
47
48    /// Hash computation error
49    #[error("Hash computation failed: {0}")]
50    HashError(String),
51}
52
53impl From<reqwest::Error> for NixError {
54    fn from(err: reqwest::Error) -> Self {
55        NixError::Http(err.to_string())
56    }
57}