make "can't follow stream paths" error a bit better (#10569)

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:🐚: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:🐚: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
This commit is contained in:
Antoine Stevan 2023-10-03 18:57:26 +02:00 committed by GitHub
parent 7c1487e18d
commit f481879ed3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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,
}),
}
}