Make get hole errors and cell path hole errors identical (improvement on #7002)#7647
Make get hole errors and cell path hole errors identical (improvement on #7002)#7647rgwood merged 5 commits intonushell:mainfrom
get hole errors and cell path hole errors identical (improvement on #7002)#7647Conversation
|
Nice! I think this is a step in the right direction. We may also need to adjust the behaviour of IMO the behaviour of |
|
I came up with an ingenious way of making |
|
Hmm, I think that change is generally a good idea but |
|
OK, I fixed it. However, I just noticed I've inadvertently changed the semantics of BEFORE: AFTER: I've decided that the latter way is better because it can interact with |
a9dafcf to
322224d
Compare
322224d to
b81dfe9
Compare
| open los_tres_amigos.json | ||
| | get amigos | ||
| | default rusty_luck 1 | ||
| | default 1 rusty_luck |
There was a problem hiding this comment.
By the way… am I losing my mind, or was this test always wrong until now? default rusty_luck 1 is not the correct order of default arguments, and never was, right?
There was a problem hiding this comment.
Suspect the test was always wrong.
FWIW I also assumed that the order was default <column name> <default value> instead of when I first encountered default, I find the current order somewhat unintuitive.
| let working_set = StateWorkingSet::new(engine_state); | ||
|
|
||
| // Value::Errors must always go to stderr, not stdout. | ||
| is_err = true; |
There was a problem hiding this comment.
Does anyone have an opinion about these lines? I don't know why Value::Errors seemingly were allowed to go to stdout, but that seemed wrong to me (and I needed to make this change to make a test pass, due to the aforementioned business about creating but not returning Value::Errors in follow_cell_path_helper().)
There was a problem hiding this comment.
I think it makes sense to force errors to stderr.
Sounds good to me - the " |
| _ => Ok(Value::int(input.into_iter().count() as i64, call.head).into_pipeline_data()), | ||
| _ => { | ||
| let mut count: i64 = 0; | ||
| // Check for and propagate errors |
There was a problem hiding this comment.
I'm a little concerned by this approach of checking for errors in downstream commands.I worry that there will be a long tail of commands where we forget to do it, leading to inconsistency. It also takes us further away from an "errors are just data" approach (which we admittedly do not adhere to very well today).
That said, users who do something like $foo | get bar | length will expect it to fail on an unsuccessful bar access... so maybe this is an OK approach for now.
In the future it would be nice if this sort of check was handled at a higher level (not sure exactly where).
There was a problem hiding this comment.
Thanks for the PR!
I think this is a good incremental improvement to cell paths. I really like that behaviour is more consistent across get and select now, and that -i no longer collapses multiple errors to a single null value.
This one will probably break a handful of scripts, and it will need an explanation in the 0.74 blog post (0.74 is being released on Jan 10): nushell/nushell.github.io#715
I'm happy to merge this, just want to get another opinion first.
|
+1 for more consistent and expected behavior |
Description
This closes #7498, as well as fixes an issue reported in #7002 (comment)
BEFORE:
AFTER:
EDIT: This also changes the semantics of
get/select-isomewhat. I've decided to leave it like this because it works more intuitively withdefaultandcompact.BEFORE:
AFTER:
User-Facing Changes
See above. EDIT: the issue with holes in cases like
[{foo: 'bar'} {}].foo.0versus[{foo: 'bar'} {}].0.foohas been resolved.Tests + Formatting
Don't forget to add tests that cover your changes.
Make sure you've run and fixed any issues with these commands:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collectto check that you're using the standard code stylecargo test --workspaceto check that all tests passAfter Submitting
If your PR had any user-facing changes, update the documentation after the PR is merged, if necessary. This will help us keep the docs up to date.