Skip to content

Strange behavior with several commands split by ';' #3585

Closed

Description

@ryanpcmcquen

Describe the bug
I get errors when I chain certain commands. Running the commands separately works fine.

To Reproduce
Steps to reproduce the behavior:

  1. brew update; brew upgrade works fine.
  2. When I run my full update command:
    brew update; brew upgrade; npm update -g; ls ~/code | where type == Dir | each { cd $it.name; git remote -v | autoview; git branch | autoview; git pull --all | autoview; cd ~/code; }; echo y | bit complete;
  3. I get errors like this while the git commands are running:
* master
Error: No such file or directory @ rb_file_s_rename - (/Users/ryanmcquenstockx/Library/Caches/Homebrew/downloads/04ce1a13fff1ee5566cf5bf2e174466e295219fa159b692125d275e1f892ca76--deno--1.11.0.catalina.bottle.tar.gz.incomplete, /Users/ryanmcquenstockx/Library/Caches/Homebrew/downloads/04ce1a13fff1ee5566cf5bf2e174466e295219fa159b692125d275e1f892ca76--deno--1.11.0.catalina.bottle.tar.gz)
remote: Enumerating objects: 14, done.
remote: Counting objects: 100% (14/14), done.
remote: Compressing objects: 100% (12/12), done.
remote: Total 12 (delta 7), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (12/12), done.

Expected behavior
This worked fine in 0.30.0.

Configuration (please complete the following information):

Run version | pivot and paste the output to show OS, features, etc.

λ version | pivot
───┬────────────────────┬─────────────────────────────────────────────────────────────────────
 # │      Column0       │                               Column1
───┼────────────────────┼─────────────────────────────────────────────────────────────────────
 0 │ version            │ 0.32.0
 1 │ build_os           │ macos-x86_64
 2 │ rust_version       │ rustc 1.51.0
 3 │ cargo_version      │ cargo 1.51.0
 4 │ pkg_version        │ 0.32.0
 5 │ build_time         │ 2021-06-01 21:00:59
 6 │ build_rust_channel │ release
 7 │ features           │ clipboard-cli, ctrlc, default, directories, dirs, ptree, rustyline,
   │                    │ term, trash, uuid, which, zip
───┴────────────────────┴─────────────────────────────────────────────────────────────────────

Activity

  1. ryanpcmcquen commented on Jun 9, 2021

    @ryanpcmcquen
    Author

    The Error line is brew failing to execute in some weird way, which I cannot reproduce when the command is isolated.

  2. ryanpcmcquen commented on Jun 9, 2021

    @ryanpcmcquen
    Author

    I think it may be related to what I reported here: #3447

  3. fdncred commented on Jun 9, 2021

    @fdncred
    Contributor

    What should be the proper option when something fails in a pipeline like this?

    1. Error out the entire pipeline?
    2. Print error messages and continue? - I guess this is what it's doing now
    3. Eat the error messages and not show you? Fail silently.
    4. have a verbose debug mode that prints "stuff" to a log file?
    5. other?

    Maybe this could be controlled by an env var?

  4. ryanpcmcquen commented on Jun 9, 2021

    @ryanpcmcquen
    Author

    Print error messages and continue? - I guess this is what it's doing now

    This is what I would expect coming from Bash. The main issue here is that it is creating errors because of the execution context ...

  5. ryanpcmcquen commented on Jun 9, 2021

    @ryanpcmcquen
    Author

    In Bash if you want it to stop on failure you would do && for chaining, rather than the ;. Not sure if nushell intends to have the same kind of distinction.

  6. sophiajt commented on Jun 9, 2021

    @sophiajt
    Contributor

    ; in nushell should be equivalent to Bash's &&. In Nushell, we use && for boolean conditions like if this && that { ... }.

  7. fdncred commented on Jun 9, 2021

    @fdncred
    Contributor

    it sounds like @jonathandturner is saying that, when using ;, and an external returns non-zero, then we should stop processing entirely showing that error.

    I think we'd need to capture return codes, which I think we tried before but perhaps reverted because not all externals are compliant with non-zero errors or 0 success. I'd like to see nushell capture error codes once again, if only to report it for things like starship. But I'm also not sure how to handle non-compliant externals.

    sounds like a great job for you @ryanpcmcquen LOL j/k. :)

  8. fdncred commented on Jun 9, 2021

    @fdncred
    Contributor

    Hey @ryanpcmcquen. What happens if you use this root config.toml value? nonzero_exit_errors = true Does it change the way your errors work?

  9. ryanpcmcquen commented on Jun 9, 2021

    @ryanpcmcquen
    Author

    I cannot reproduce the error with that setting. Although it does make the shell think one of the update commands is failing.

  10. fdncred commented on Jun 9, 2021

    @fdncred
    Contributor

    you can see what is going on here. apparently something is returning a non-zero value.

    // We can give an error when we see a non-zero exit code, but this is different
    // than what other shells will do.
    let external_failed = match child.wait() {
        Err(_) => true,
        Ok(exit_status) => !exit_status.success(),
    };
    
    if external_failed {
        let cfg = nu_data::config::config(Tag::unknown());
        if let Ok(cfg) = cfg {
            if cfg.contains_key("nonzero_exit_errors") {
                let _ = stdout_read_tx.send(Ok(Value {
                    value: UntaggedValue::Error(ShellError::labeled_error(
                        "External command failed",
                        "command failed",
                        &stdout_name_tag,
                    )),
                    tag: stdout_name_tag.clone(),
                }));
            }
        }
        let _ = stdout_read_tx.send(Ok(Value {
            value: UntaggedValue::Error(ShellError::external_non_zero()),
            tag: stdout_name_tag,
        }));
    }
  11. github-actions commented on Jul 10, 2021

    @github-actions

    This issue is being marked stale because it has been open for 30 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active.

  12. github-actions commented on Oct 9, 2021

    @github-actions

    This issue is being marked stale because it has been open for 90 days without activity. If you feel that this is in error, please comment below and we will keep it marked as active. Otherwise, it will be closed in 10 days.

  13. sholderbach commented on Dec 1, 2022

    @sholderbach
    Member

    Just wanted to check-in if this still fails unexpectedly? We should stop on errors in a ; chain now. (It basically replaces && in bash. And with 0.72 we introduced try/catch as a more explicit substitute for || in bash

  14. added
    A:error-handling
    on Dec 1, 2022
  15. sophiajt commented on Aug 9, 2023

    @sophiajt
    Contributor

    Closing as no-repro as we've done a lot of improvements to ; since this was filed.

    Please re-open if the issue returns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A:error-handling

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions