flake_edit/
error.rs

1use thiserror::Error;
2
3use crate::validate::ValidationError;
4use crate::walk::WalkerError;
5
6#[derive(Debug, Error)]
7pub enum FlakeEditError {
8    #[error("IoError: {0}")]
9    Io(#[from] std::io::Error),
10    #[error(transparent)]
11    Walker(#[from] WalkerError),
12    #[error("Lock file missing root node")]
13    LockMissingRoot,
14    #[error("There is an error in the Lockfile: {0}")]
15    LockError(String),
16    #[error("Deserialization Error: {0}")]
17    Serde(#[from] serde_json::Error),
18    #[error(
19        "Input '{0}' already exists in the flake.\n\nTo replace it:\n  1. Remove it first: flake-edit remove {0}\n  2. Then add it again: flake-edit add {0} <flakeref>\n\nOr add it with a different [ID]:\n  flake-edit add [ID] <flakeref>\n\nTo see all current inputs: flake-edit list"
20    )]
21    DuplicateInput(String),
22    #[error(
23        "Input '{0}' not found in the flake.\n\nTo add it:\n  flake-edit add {0} <flakeref>\n\nTo see all current inputs: flake-edit list"
24    )]
25    InputNotFound(String),
26    #[error("Validation error in flake.nix:\n{}", format_validation_errors(.0))]
27    Validation(Vec<ValidationError>),
28}
29
30fn format_validation_errors(errors: &[ValidationError]) -> String {
31    errors
32        .iter()
33        .map(|e| format!("  - {}", e))
34        .collect::<Vec<_>>()
35        .join("\n")
36}