Skip to content

Make Semicolon stop on error - #6079

Merged
fdncred merged 6 commits into
nushell:mainfrom
WindSoilder:semicolon
Jul 20, 2022
Merged

fdncred merged 6 commits into
nushell:mainfrom
WindSoilder:semicolon

Conversation

@WindSoilder

@WindSoilder WindSoilder commented Jul 19, 2022 •

Copy link
Copy Markdown
Contributor

Description

Fixes #6022, for the following command:

^ls asdfasd ; echo done

if ^ls asdfasd failed, echo done will never executed again.

Here is executing result:
img

As we can see, echo done is not executed.

But......Additional note

when external command failed, the relative output can be too verbose, I'm not sure if this is ok:
img

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

@WindSoilder WindSoilder changed the title Make Semicolon stop on error, so it behaves like && in bash Make Semicolon stop on error Jul 19, 2022
@elferherrera

Copy link
Copy Markdown
Contributor

I think for externals nu shouldn't show an error

@WindSoilder

Copy link
Copy Markdown
Contributor Author

I think for externals nu shouldn't show an error

Agreed, sorry for that I don't have ideas to achieve it, any ideas?

I found that if eval returns Err(ShellError), then the error message will be shown by nu

@fdncred

fdncred commented Jul 19, 2022

Copy link
Copy Markdown
Contributor

i'm wondering if external errors are being sent to stderr and nushell just doesn't see it? i.e. if you run this through | complete i wonder if it would be captured.

@sophiajt

Copy link
Copy Markdown
Contributor

for the "2nd part, output by nushell" I don't think we can print an exit code error message unless the user says they want it. Sometimes apps (like git) will output non-zero exit codes.

I wrote about this a bit: https://www.jntrnr.com/exit-codes/

@WindSoilder

Copy link
Copy Markdown
Contributor Author

Thanks for feedback, mark as draft for now until I get a proper solution

@WindSoilder
WindSoilder marked this pull request as draft July 20, 2022 01:20
@WindSoilder

WindSoilder commented Jul 20, 2022 •

Copy link
Copy Markdown
Contributor Author

Ok here is the new result:
img

To make it works properly, I have to change eval_expression_with_input's prototype, so caller can know about external command failed.


i'm wondering if external errors are being sent to stderr and nushell just doesn't see it? i.e. if you run this through | complete i wonder if it would be captured.

@fdncred It's not captured in latest main

❯ ^ls asdfa | complete
ls: asdfa: No such file or directory
╭───────────┬───╮
│ stdout    │   │
│ stderr    │   │
│ exit_code │ 1 │
╰───────────┴───╯

@WindSoilder
WindSoilder marked this pull request as ready for review July 20, 2022 02:37
@fdncred

fdncred commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

It's not captured in latest main

Thanks for checking. That seems like a bug in another place.

Mac must be a little different because I get a different exit code.

> ^ls adfadf | complete 
ls: cannot access 'adfadf': No such file or directory
╭───────────┬───╮
│ stdout    │   │
│ stderr    │   │
│ exit_code │ 2 │
╰───────────┴───╯

maybe the only way to capture stderr right now is with do?

> do -i { ^ls adsfd | complete } 
╭───────────┬──────────────────────────────────────────────────────╮
│ stdout    │                                                      │
│ stderr    │ ls: cannot access 'adsfd': No such file or directory │
│           │                                                      │
│ exit_code │ 2                                                    │
╰───────────┴──────────────────────────────────────────────────────╯

@WindSoilder

Copy link
Copy Markdown
Contributor Author

I think this is the reason, when repl, nu doesn't redirect stderr

match eval_block(engine_state, stack, &block, input, false, false) {

@fdncred

fdncred commented Jul 20, 2022

Copy link
Copy Markdown
Contributor

I think this is the reason, when repl, nu doesn't redirect stderr

I wonder if it should redirect stderr?

Let's run with this one for now and see what happens. Thanks!

@fdncred
fdncred merged commit a35a71f into nushell:main Jul 20, 2022
@WindSoilder
WindSoilder deleted the semicolon branch July 21, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Semicolon doesn't stop on error with cmake or make

4 participants