Better error handling using do (#5890)

* adds `capture-errors` flag for `do`

* adds `get-type` core command to get type

* fmt

* add tests in example

* fmt

* fix tests

* manually revert previous changes related to `get-type`

* adds method to check for error name using `into string`

* fix clippy
This commit is contained in:
pwygab
2022-06-30 09:01:34 +08:00
committed by GitHub
parent 6ee13126f7
commit a0db4ce747
8 changed files with 62 additions and 4 deletions

View File

@ -0,0 +1,13 @@
use nu_test_support::{nu, pipeline};
#[test]
fn capture_errors_works() {
let actual = nu!(
cwd: ".", pipeline(
r#"
do -c {$env.use} | describe
"#
));
assert_eq!(actual.out, "error");
}

View File

@ -9,6 +9,7 @@ mod cp;
mod date;
mod def;
mod default;
mod do_;
mod drop;
mod each;
mod echo;

View File

@ -171,3 +171,15 @@ fn from_nothing() {
assert_eq!(actual.out, "");
}
#[test]
fn from_error() {
let actual = nu!(
cwd: ".", pipeline(
r#"
do -c {$env.use} | into string
"#
));
assert_eq!(actual.out, "nu::shell::name_not_found");
}