Skip to content

return Error if get meet nothing and without "i"#7002

Merged
kubouch merged 1 commit intonushell:mainfrom
Decodetalkers:get_ignore_error
Dec 31, 2022
Merged

return Error if get meet nothing and without "i"#7002
kubouch merged 1 commit intonushell:mainfrom
Decodetalkers:get_ignore_error

Conversation

@Decodetalkers
Copy link
Copy Markdown
Contributor

@Decodetalkers Decodetalkers commented Nov 4, 2022

Description

relate issue #6969

before:
image

after
image

Tests

Make sure you've done the following:

  • Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.
  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.
  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

Documentation

@Decodetalkers Decodetalkers changed the title feat: show error when meet nothing without key "i" return Error if get meet nothing and without "i" Nov 4, 2022
@Decodetalkers
Copy link
Copy Markdown
Contributor Author

And I think the error is a bit mixing, both get and select, should show that there are empty cell ,so cannot get message, I think

@Decodetalkers Decodetalkers force-pushed the get_ignore_error branch 4 times, most recently from 49ba1b4 to 3dbe1fe Compare November 4, 2022 06:56
@sholderbach sholderbach added the notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes label Nov 11, 2022
@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented Dec 8, 2022

Hi, can you please add some examples to this PR? It's not obvious to me what this PR is fixing. It would help to see:

  1. A "before" example where some Nu code did not work correctly
  2. An "after" example showing the fixed behaviour

@Decodetalkers
Copy link
Copy Markdown
Contributor Author

Emm, since the action of select is changed, so if still need this change described in this issue?

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Dec 10, 2022

I think I finally understand this PR. You just want to make get work more like select works, which is, if there's an empty cell, select shows and error. Right now get doesn't show an error. I agree that it probably should if we're going to be consistent.

We might want to unite the error messages so they say similar things and point to similar places.

Screenshot 2022-12-10 at 7 11 22 AM

Although it looks like select -i may be broken? But that is unrelated to this PR.
Screenshot 2022-12-10 at 7 13 54 AM

@Decodetalkers
Copy link
Copy Markdown
Contributor Author

I think I finally understand this PR. You just want to make get work more like select works, which is, if there's an empty cell, select shows and error. Right now get doesn't show an error. I agree that it probably should if we're going to be consistent.

We might want to unite the error messages so they say similar things and point to similar places.

Screenshot 2022-12-10 at 7 11 22 AM

Although it looks like select -i may be broken? But that is unrelated to this PR. Screenshot 2022-12-10 at 7 13 54 AM

Emm, in that issue, you think not show the empty error is a bug of get, and I agree of it , so I make a pull request, but I have found the behavior of select has changed..

But I think get and selected should show the message..I do not much agree about the new behavior of select.. But since now the behavior of select has changed, so I don't know if the pull request should still exist..

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Dec 10, 2022

But I think get and selected should show the message

I agree. I'm interested what others think too.

@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Dec 30, 2022

@Decodetalkers The errors on get are more descriptive than what is on select. If you can update the select error messages I think we can land this and see how it goes.

@Decodetalkers
Copy link
Copy Markdown
Contributor Author

@Decodetalkers The errors on get are more descriptive than what is on select. If you can update the select error messages I think we can land this and see how it goes.

#7639 pull request is here now

@kubouch
Copy link
Copy Markdown
Contributor

kubouch commented Dec 31, 2022

Let's give it a try since I merged the other PR as well. Thanks!

@kubouch kubouch merged commit 81a7d17 into nushell:main Dec 31, 2022
@Decodetalkers Decodetalkers deleted the get_ignore_error branch December 31, 2022 11:33
@rgwood
Copy link
Copy Markdown
Contributor

rgwood commented Jan 1, 2023

I'm not sure we landed in a good state after merging this PR. get foo now behaves differently than .foo, which I think is undesirable:

〉[{foo: 'bar'} {}].foo
╭───┬─────╮
│ 0 │ bar │
│ 1 │     │
╰───┴─────╯
〉[{foo: 'bar'} {}] | get foo
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── value originates here
   ·         ╰── cannot find column 'Empty cell'
   ╰────

The error messages also need work; they should look more like this:

〉[{foo: 'bar'} {}] | get foo
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── cannot find column 'foo' 
   ·         ╰── value originates here
   ╰────

I took a quick look and think that fixing that error message is going to be difficult due to the way this was implemented.

@Decodetalkers
Copy link
Copy Markdown
Contributor Author

Decodetalkers commented Jan 1, 2023

I'm not sure we landed in a good state after merging this PR. get foo now behaves differently than .foo, which I think is undesirable:

〉[{foo: 'bar'} {}].foo
╭───┬─────╮
│ 0 │ bar │
│ 1 │     │
╰───┴─────╯
〉[{foo: 'bar'} {}] | get foo
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── value originates here
   ·         ╰── cannot find column 'Empty cell'
   ╰────

The error messages also need work; they should look more like this:

〉[{foo: 'bar'} {}] | get foo
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── cannot find column 'foo' 
   ·         ╰── value originates here
   ╰────

I took a quick look and think that fixing that error message is going to be difficult due to the way this was implemented.

Because in the related issue, author think in select, nushell will check empty cell, but get will not check, so I think get can also have the ability to check empty cell.. so add the key i to check it.. and with .foo, we cannot pass any key to it , so do not check it is better I think

Oh , I have seen your pull request , add ! and ? will be good..

rgwood pushed a commit that referenced this pull request Jan 2, 2023
…nt on #7002) (#7647)

# Description

This closes #7498, as well as fixes an issue reported in
#7002 (comment)

BEFORE:
```
〉[{foo: 'bar'} {}] | get foo
Error: nu::shell::column_not_found (link)

  × Cannot find column
   ╭─[entry #5:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   · ────────┬────────   ─┬─
   ·         │            ╰── value originates here
   ·         ╰── cannot find column 'Empty cell'
   ╰────

〉[{foo: 'bar'} {}].foo
╭───┬─────╮
│ 0 │ bar │
│ 1 │     │
╰───┴─────╯
```
AFTER:
```
〉[{foo: 'bar'} {}] | get foo
Error: nu:🐚:column_not_found (link)

  × Cannot find column
   ╭─[entry #1:1:1]
 1 │ [{foo: 'bar'} {}] | get foo
   ·               ─┬        ─┬─
   ·                │         ╰── cannot find column 'foo'
   ·                ╰── value originates here
   ╰────

〉[{foo: 'bar'} {}].foo
Error: nu:🐚:column_not_found (link)

  × Cannot find column
   ╭─[entry #3:1:1]
 1 │ [{foo: 'bar'} {}].foo
   ·               ─┬  ─┬─
   ·                │   ╰── cannot find column 'foo'
   ·                ╰── value originates here       
   ╰────
```

EDIT: This also changes the semantics of `get`/`select` `-i` somewhat.
I've decided to leave it like this because it works more intuitively
with `default` and `compact`.
BEFORE:
```
〉[{a:1} {b:2} {a:3}] | select -i foo | to nuon
null
```
AFTER:
```
〉[{a:1} {b:2} {a:3}] | select -i foo | to nuon
[[foo]; [null], [null], [null]]
```

# User-Facing Changes

See above. EDIT: the issue with holes in cases like ` [{foo: 'bar'}
{}].foo.0` versus ` [{foo: 'bar'} {}].0.foo` has 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 -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

notes:breaking-changes This PR implies a change affecting users and has to be noted in the release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants