Skip to content

Fix ls behaviour when directory is empty - #8439

Merged
sophiajt merged 1 commit into
nushell:mainfrom
rgwood:fix-ls-empty
Mar 15, 2023
Merged

sophiajt merged 1 commit into
nushell:mainfrom
rgwood:fix-ls-empty

Conversation

@rgwood

@rgwood rgwood commented Mar 13, 2023

Copy link
Copy Markdown
Contributor

Prior to this PR, ls would return nothing in an empty directory. After this PR, it returns an empty List. This makes the behaviour of ls more consistent and easier to reason about (IMO).

This was prompted by a user noticing that ls | where size == 0KB and type == file breaks when run in an empty directory:

  × Input type not supported.
   ╭─[entry #12:1:1]
 1 │ ls | where size == 0KB and type == file
   · ─┬   ──┬──
   ·  │     ╰── only list, binary, raw data or range input data is supported
   ·  ╰── input type: nothing
   ╰────

If people agree with this change, let's wait until after the 0.77 release so we have a bit more time to test it.

@sholderbach sholderbach left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes also sense from a perspective of consistent types.

@codecov

codecov Bot commented Mar 13, 2023

Copy link
Copy Markdown

Codecov Report

Merging #8439 (f1f1306) into main (86faf75) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #8439   +/-   ##
=======================================
  Coverage   68.50%   68.50%           
=======================================
  Files         620      620           
  Lines       99723    99723           
=======================================
  Hits        68316    68316           
  Misses      31407    31407           
Impacted Files Coverage Δ
crates/nu-command/src/filesystem/ls.rs 80.25% <100.00%> (ø)

... and 4 files with indirect coverage changes

@sophiajt
sophiajt merged commit 57ce6a7 into nushell:main Mar 15, 2023
sophiajt pushed a commit that referenced this pull request Jun 20, 2023
In my view we should revert #8395 for now

## Potentially inconsistent application of semantic change
#8395 (1d5e7b4) was loosening the type
coercion rules significantly, to let missing data / void returns that
were either expressed by `PipelineData::Empty` or the `Value::nothing`
be accept by specifically those commands/operations that made use of
`PipelineData::into_iter_strict()`. This could apply the new rules
inconsistently.

## Turning explicit failures into silent continuations
Furthermore the effect of this breaking change to the missing data
semantics could make previous errors into silent failures.
This could either just reduce the effectiveness of teaching error
messages in interactive use:

### Contrived example before
```bash
> cd . | where blah
Error: nu::shell::only_supports_this_input_type

  × Input type not supported.
   ╭─[entry #13:1:1]
 1 │ cd . | where blah
   ·        ──┬──┬
   ·          │  ╰── input type: null
   ·          ╰── only list, binary, raw data or range input data is supported
   ╰────
```
### ...after, with #8395
```bash
> cd . | where blah
╭────────────╮
│ empty list │
╰────────────╯
```

In rare cases people could already try to rely on catching an error of a
downstream command to actually deal with the missing data, so it would
be a breaking change for their existing code.

## Problem with `PipelineData::into_iter_strict()`

Maybe this makes `_strict` a bit of a misnomer for this particular
iterator construction.
Further we did not actively test the `PipelineData::empty` branch before

![grafik](https://github.com/nushell/nushell/assets/15833959/c377bf1d-d47c-4c25-a342-9a348539f242)

## Parsimonious solution exists

For the motivating issue #8393
there already exists a fix that makes `ls` more consistent with the type
system by returning an empty `Value::List`
#8439
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.

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

4 participants