Skip to content

Variable assignment fails due to piping no values in an empty directory #8393

Description

@guilt

Question

How do I assign variables when I'm in an empty directory?

let x = (ls | where size >= 2kB)
Error: nu::shell::only_supports_this_input_type (link)

  × Input type not supported.
   ╭─[entry #12:1:1]
 1 │ let x = (ls | where size >= 2kB)
   ·          ─┬   ──┬──
   ·           │     ╰── only list, binary, raw data or range input data is supported
   ·           ╰── input type: nothing
   ╰────

I guess, returning an empty list may still be okay?

Additional context and details

No response

Activity

  1. added
    deprecated:question
    on Mar 10, 2023
  2. ahkrr commented on Mar 10, 2023

    @ahkrr
    Contributor

    You can ignore errors with the do command. You can read help do
    let x = do -i {ls | where size >= 2kB }
    You can use the newer try catch construct. help try
    let x = try { ls | where size >= 2kB } catch { [] }

  3. added
    A:error-handling
    on Mar 10, 2023
  4. amtoine commented on Jun 18, 2023

    @amtoine
    Member

    i cannot reproduce this with the latest revision of Nushell 🤔

    EDIT: looks to me it's because now ls returns an empty list when the directory is empty 👌
    doing a git bisect and running the following command

    cargo run -- -c "print $'(ls /tmp/empty | describe) (char lparen)(ls /tmp/empty | length)(char rparen)'"

    to see the type returned by ls and the length of the table (/tmp/empty is an empty directory)

    the output was nothing (0) on ccd72fa, i.e. just before this issue and is now, i.e. on 6c730de, list<any> (0), explaining why this works now 😌

  5. linked a pull request that will close this issueFix ls behaviour when directory is empty #8439on Jun 18, 2023
  6. added a commit that references this issue on Jun 18, 2023
    1d5e7b4
  7. added a commit that references this issue on Jun 20, 2023
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-handlingdeprecated:question

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions