nu_protocol/errors/
config.rs1#![allow(unused_assignments)]
2use crate::{ShellError, Span, Type};
3use miette::Diagnostic;
4use std::hash::Hash;
5use thiserror::Error;
6
7#[derive(Clone, Debug, PartialEq, Error, Diagnostic)]
9pub enum ConfigError {
10 #[error("Type mismatch at {path}")]
11 #[diagnostic(code(nu::shell::type_mismatch), help("{help}"))]
12 TypeMismatch {
13 path: String,
14 expected: Type,
15 actual: Type,
16 #[label = "expected {expected}, but got {actual}"]
17 span: Span,
18 help: String,
20 },
21 #[error("Invalid value for {path}")]
22 #[diagnostic(code(nu::shell::invalid_value))]
23 InvalidValue {
24 path: String,
25 valid: String,
26 actual: String,
27 #[label = "expected {valid}, but got {actual}"]
28 span: Span,
29 },
30 #[error("Unknown config option: {path}")]
31 #[diagnostic(code(nu::shell::unknown_config_option))]
32 UnknownOption {
33 path: String,
34 #[label("remove this")]
35 span: Span,
36 },
37 #[error("{path} requires a '{column}' column")]
38 #[diagnostic(code(nu::shell::missing_required_column))]
39 MissingRequiredColumn {
40 path: String,
41 column: &'static str,
42 #[label("has no '{column}' column")]
43 span: Span,
44 },
45 #[error("{path} is deprecated")]
46 #[diagnostic(
47 code(nu::shell::deprecated_config_option),
48 help("please {suggestion} instead")
49 )]
50 Deprecated {
51 path: String,
52 suggestion: &'static str,
53 #[label("deprecated")]
54 span: Span,
55 },
56 #[error("{path} cannot be changed after Nushell has started")]
57 #[diagnostic(
58 code(nu::shell::config_option_locked_after_startup),
59 help(
60 "set {path} in your config.nu (or via --config / the relevant env var) and restart Nushell"
61 )
62 )]
63 LockedAfterStartup {
64 path: String,
65 #[label("cannot be changed at runtime")]
66 span: Span,
67 },
68 #[error(transparent)]
70 #[diagnostic(transparent)]
71 ShellError(#[from] ShellError),
72}
73
74#[derive(Clone, Debug, PartialEq, Error, Diagnostic)]
76#[diagnostic(severity(Warning))]
77pub enum ConfigWarning {
78 #[error("Incompatible options")]
79 #[diagnostic(code(nu::shell::incompatible_options), help("{help}"))]
80 IncompatibleOptions {
81 label: &'static str,
82 #[label = "{label}"]
83 span: Span,
84 help: &'static str,
85 },
86}
87
88impl Hash for ConfigWarning {
90 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
91 match self {
92 ConfigWarning::IncompatibleOptions { label, help, .. } => {
93 label.hash(state);
94 help.hash(state);
95 }
96 }
97 }
98}