Skip to content

make the "External command failed" error more descriptive #8313

Closed

Description

@amtoine

Related problem

i often use the fzf fuzzy finder in nushell pipelines but i have a problem when not piping its output to str trim

according to @fdncred, the behaviour in https://asciinema.org/a/564496 is expected 👌

Note
code:

>_ let var = ("yes\nno" | to text | fzf | str trim); $var
yes
>_ let var = ("yes\no" | to text | fzf); $var
Error: nu::shell::external_command

  × External command failed
   ╭─[entry #4:1:1]
 1 │ let var = ("yes\no" | to text | fzf); $var
   ·                                 ─┬─
   ·                                  ╰── External command failed
   ╰────
  help:

however, i find the error in itself not very descriptive 🤔
because, in the end, fzf does not fail at all here! 😮

Describe the solution you'd like

i'm not sure what the issue with fzf without str trim here is, so i do not know what the message should be 🤔

however, i'm pretty sure the fzf external command did NOT fail, so the error message should probably NOT be "External command failed" 😋

Describe alternatives you've considered

No response

Additional context and details

No response

Activity

  1. added
    category:enhancement
    on Mar 4, 2023
  2. added
    A:external-commands
    A:error-unhelpful
    on Mar 4, 2023
  3. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    I figure the failure is because fzf is returning with some odd character. Maybe a newline or a \0 or a space. We could probably figure out what it's returning.

  4. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    ok, this is what I found

    1. firstly "yes\no" shows up as o and yes because double quotes interprets \n as an escape.
    2. You can see what fzf is returning like this
    "yes\no" | to text | fzf | debug -r 
    String {
        val: "yes\n",
        span: Span {
            start: 198040,
            end: 198043,
        },
    }
    

    The \n is throwing things off. Having items in a list and stripping the \n with str trim

    This seems to work better

    [yes no] | to text | fzf | str trim | debug -r  
    String {
        val: "no",
        span: Span {
            start: 198127,
            end: 198135,
        },
    }
    

    I think the reason that this is expected is it's hard to tell if and when we should strip the newline. Maybe I'm wrong and there is a good heuristic that we could use or that we're already using and it just being missed here somehow.

  5. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    BTW - I agree, that 'external command failed' isn't super helpful considering what the problem is here.

  6. amtoine commented on Mar 4, 2023

    @amtoine
    MemberAuthor
    1. firstly "yes\no" shows up as o and yes because double quotes interprets \n as an escape.

    woopsie, i forgot the "n", that's on me 😌

    The \n is throwing things off.

    yeah, probably

    BTW - I agree, that 'external command failed' isn't super helpful considering what the problem is here.

    if there is an "easy" change to be made, maybe it's on this error message?

    => something that looks odd to me is that, as you can see in the recording, fzf does not even launch when ommiting the str trim 🤔
    it just hangs and i have to kill fzf to see the error...

  7. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    fzf does not even launch when ommiting the str trim

    I don't have this issue on macos. it launches fine without str trim.

  8. amtoine commented on Mar 4, 2023

    @amtoine
    MemberAuthor

    I don't have this issue on macos. it launches fine without str trim.

    oooh 🤔
    interesting

    because, i might have been unclear but yeah the real strange thing is that fzf does not show up at all 😱

    i can reproduce that on my work machine, so on ubuntu, as well as on arch

  9. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    I know that fzf reads env vars before/while launching. Do you have any of those set that could be affecting how it runs?

  10. amtoine commented on Mar 4, 2023

    @amtoine
    MemberAuthor

    I know that fzf reads env vars before/while launching. Do you have any of those set that could be affecting how it runs?

    the only thing i have is FZF_DEFAULT_OPTS i think, but i've got the same issue with

    with-env [FZF_DEFAULT_OPTS ""] { let var = ([yes no] | to text | fzf) }
  11. amtoine commented on Mar 4, 2023

    @amtoine
    MemberAuthor

    and this "hanging" issue only occurs when i try to let var = ( ... | fzf)❕

  12. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    oh ya, i didn't try to assign it a variable. let me try that.

  13. fdncred commented on Mar 4, 2023

    @fdncred
    Contributor

    ya, it breaks without the str trim for me too when assigning to a var

  14. amtoine commented on Mar 4, 2023

    @amtoine
    MemberAuthor

    ya, it breaks without the str trim for me too when assigning to a var

    aah cool, we're on the same page then 💪
    yep i tried to assign the result to a variable, that's the crucial part of the problem i think, and it hangs

  15. WindSoilder commented on Mar 4, 2023

    @WindSoilder
    Contributor

    Sorry, I believe #8204 is the one to blame..

  16. added a commit that references this issue on Mar 16, 2023
    31d9c08
  17. added this to the v0.78.0 milestone on Mar 17, 2023
  18. added a commit that references this issue on Mar 17, 2023
    716c144
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-unhelpfulA:external-commandscategory:enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions