From f481879ed389582d9849ba91b56468f14089798d Mon Sep 17 00:00:00 2001 From: Antoine Stevan <44101798+amtoine@users.noreply.github.com> Date: Tue, 3 Oct 2023 18:57:26 +0200 Subject: [PATCH] make "can't follow stream paths" error a bit better (#10569) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit related to - https://github.com/nushell/nushell/issues/9373 - https://github.com/nushell/nushell/issues/8639 might be able to close https://github.com/nushell/nushell/issues/8639? # Description "can't follow stream paths" errors have always been a bit scary and obnoxious because they give no information about what happens... in this PR i try to slightly improve the error message by telling if the stream was empty or not and give span information when available. # User-Facing Changes ```nushell > update value (get value) Error: nu::shell::incompatible_path_access × Data cannot be accessed with a cell path ╭─[entry #1:1:1] 1 │ update value (get value) · ─┬─ · ╰── empty pipeline doesn't support cell paths ╰──── ``` ```nushell > ^echo "foo" | get 0 Error: nu::shell::incompatible_path_access × Data cannot be accessed with a cell path ╭─[entry #2:1:1] 1 │ ^echo "foo" | get 0 · ──┬─ · ╰── external stream doesn't support cell paths ╰──── ``` # Tests + Formatting # After Submitting --- crates/nu-protocol/src/pipeline_data.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crates/nu-protocol/src/pipeline_data.rs b/crates/nu-protocol/src/pipeline_data.rs index f9b1c1220b..cf96eca13e 100644 --- a/crates/nu-protocol/src/pipeline_data.rs +++ b/crates/nu-protocol/src/pipeline_data.rs @@ -393,7 +393,14 @@ impl PipelineData { Value::list(stream.collect(), head).follow_cell_path(cell_path, insensitive) } PipelineData::Value(v, ..) => v.follow_cell_path(cell_path, insensitive), - _ => Err(ShellError::IOError("can't follow stream paths".into())), + PipelineData::Empty => Err(ShellError::IncompatiblePathAccess { + type_name: "empty pipeline".to_string(), + span: head, + }), + PipelineData::ExternalStream { span, .. } => Err(ShellError::IncompatiblePathAccess { + type_name: "external stream".to_string(), + span, + }), } }