nu_protocol/errors/
shell_warning.rs1#![allow(unused_assignments)]
2use crate::Span;
3use miette::Diagnostic;
4use std::hash::Hash;
5use thiserror::Error;
6
7use crate::{ConfigWarning, ReportMode, Reportable};
8
9#[derive(Clone, Debug, Error, Diagnostic)]
10#[diagnostic(severity(Warning))]
11pub enum ShellWarning {
12 #[error("{dep_type} deprecated.")]
17 #[diagnostic(code(nu::shell::deprecated))]
18 Deprecated {
19 dep_type: String,
20 label: String,
21 #[label("{label}")]
22 span: Span,
23 #[help]
24 help: Option<String>,
25 report_mode: ReportMode,
26 },
27 #[error("Encountered {} warnings(s) when updating config", warnings.len())]
29 #[diagnostic(code(nu::shell::invalid_config))]
30 InvalidConfig {
31 #[related]
32 warnings: Vec<ConfigWarning>,
33 },
34}
35
36impl Reportable for ShellWarning {
37 fn report_mode(&self) -> ReportMode {
38 match self {
39 ShellWarning::Deprecated { report_mode, .. } => *report_mode,
40 ShellWarning::InvalidConfig { .. } => ReportMode::FirstUse,
41 }
42 }
43}
44
45impl Hash for ShellWarning {
47 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
48 match self {
49 ShellWarning::Deprecated {
50 dep_type, label, ..
51 } => {
52 dep_type.hash(state);
53 label.hash(state);
54 }
55 ShellWarning::InvalidConfig { .. } => (),
57 }
58 }
59}