nu_protocol/config/
display_errors.rs

1use super::prelude::*;
2use crate as nu_protocol;
3use crate::ShellError;
4
5#[derive(Clone, Copy, Debug, IntoValue, PartialEq, Eq, Serialize, Deserialize)]
6pub struct DisplayErrors {
7    pub exit_code: bool,
8    pub termination_signal: bool,
9}
10
11impl DisplayErrors {
12    pub fn should_show(&self, error: &ShellError) -> bool {
13        match error {
14            ShellError::NonZeroExitCode { .. } => self.exit_code,
15            #[cfg(unix)]
16            ShellError::TerminatedBySignal { .. } => self.termination_signal,
17            _ => true,
18        }
19    }
20}
21
22impl Default for DisplayErrors {
23    fn default() -> Self {
24        Self {
25            exit_code: false,
26            termination_signal: true,
27        }
28    }
29}
30
31impl UpdateFromValue for DisplayErrors {
32    fn update<'a>(
33        &mut self,
34        value: &'a Value,
35        path: &mut ConfigPath<'a>,
36        errors: &mut ConfigErrors,
37    ) {
38        let Value::Record { val: record, .. } = value else {
39            errors.type_mismatch(path, Type::record(), value);
40            return;
41        };
42
43        for (col, val) in record.iter() {
44            let path = &mut path.push(col);
45            match col.as_str() {
46                "exit_code" => self.exit_code.update(val, path, errors),
47                "termination_signal" => self.termination_signal.update(val, path, errors),
48                _ => errors.unknown_option(path, val),
49            }
50        }
51    }
52}