Skip to main content

nu_config/
errors.rs

1use std::path::PathBuf;
2
3/// Errors that can occur during config-path resolution.
4///
5/// These are deliberately **not** `ShellError` — this crate sits below
6/// `nu-protocol` in the dependency graph. Callers convert to `ShellError` at
7/// the boundary.
8///
9/// Non-fatal XDG issues are **not** errors — they are [`ConfigWarning`]s.
10#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
11pub enum ConfigError {
12    /// No config directory could be resolved (no XDG env var and the platform
13    /// fallback returned `None`).
14    #[error("Could not determine a config directory")]
15    ConfigDirNotFound,
16
17    /// No home directory could be found via the platform home-dir lookup.
18    #[error("Could not determine the home directory")]
19    NoHomeDir,
20}
21
22/// Non-fatal warnings produced during config-path resolution.
23#[derive(Debug, Clone, PartialEq, Eq, derive_more::Display)]
24pub enum ConfigWarning {
25    /// `$XDG_CONFIG_HOME` was set to a non-absolute value and was ignored; the
26    /// platform default was used instead. Not emitted when `--config-home`
27    /// simply overrides a valid XDG value.
28    #[display(
29        "$env.XDG_CONFIG_HOME ({xdg}) is set to a non-absolute path, \
30        using default config directory instead: {}", 
31        resolved.display(),
32    )]
33    XdgConfigIgnored { xdg: String, resolved: PathBuf },
34
35    /// The old config directory (platform default) has files but the new
36    /// XDG_CONFIG_HOME directory is empty — the user may have forgotten to
37    /// migrate.
38    #[display(
39        "WARNING: XDG_CONFIG_HOME has been set but {} is empty.\n\
40        Nushell will not move your configuration files from {}", 
41        new.display(),
42        old.display(),
43    )]
44    OldConfigDirHasFiles { old: PathBuf, new: PathBuf },
45}