Skip to content

mkdir: don't interrupt when error happened - #18195

Merged
WindSoilder merged 1 commit into
nushell:mainfrom
WindSoilder:push-zrotxpvlnnzr
May 15, 2026
Merged

WindSoilder merged 1 commit into
nushell:mainfrom
WindSoilder:push-zrotxpvlnnzr

Conversation

@WindSoilder

Copy link
Copy Markdown
Contributor

Description

This pr makes mkdir handle all non-error conditions through completion.

User-facing changes (Release notes)

mkdir will try to create all directories, even if errors happened in the middle

# Assume you are inside `/tmp` directory
> mkdir a
> chmod 400 a
> mkdir b a/c
Error: nu::shell::error

  × Permission denied
   ╭─[repl_entry #24:1:9]
 1 │ mkdir b a/c
   ·         ─┬─
   ·          ╰── Permission denied
   ╰────
> "b" | path exists
true

Also noted that the errors are pointed to correct span. Previously it points to crates/nu-command/src/filesystem/umkdir.rs:95:48, which is not user friendly.

Additional notes

related: #15413

@WindSoilder WindSoilder added notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes A:commands General additions or changes to commands labels May 13, 2026
@WindSoilder
WindSoilder force-pushed the push-zrotxpvlnnzr branch 2 times, most recently from 2d01d6d to a0374b9 Compare May 13, 2026 08:55
@WindSoilder
WindSoilder merged commit aaf4fb7 into nushell:main May 15, 2026
17 checks passed
WindSoilder added a commit that referenced this pull request May 15, 2026
…error happened (#18202)

## Description
As title, this pr going to make `rm` works consistently with `mkdir`,
which is changed in #18195

To implement this, I need to change early return logic on error case,
for any lines returns an Err early, it invokes `collect_rm_result`
closure instead, which pushes result to `verbose_out` if `verbose` is
set, and may set `first_error` variable if rm results to error.

Finally instead of returning `Pipeline::empty`, it may return:
- Pipeline::value(Value::list(verbose_out)) if verbose is set
- Error if verbose is not set and there is an error
- Pipeline::empty

## User-facing changes (Release notes)
### `rm -v` returns structured data
```
> rm -v z a c
╭───┬────────┬─────────┬───────────╮
│ # │  path  │ deleted │   error   │
├───┼────────┼─────────┼───────────┤
│ 0 │ /tmp/z │ false   │ Not found │
│ 1 │ /tmp/c │ false   │ Not found │
│ 2 │ /tmp/a │ true    │           │
╰───┴────────┴─────────┴───────────╯
```
### `rm` removes other files even if there is an error in the middle
```
> touch a
> rm z c a
Error: nu::shell::io::not_found

  × Not found
   ╭─[repl_entry #7:1:6]
 1 │ rm z c a
   ·      ┬
   ·      ╰── Not found
   ╰────
  help: '/tmp/c' does not exist

Error: nu:🐚:io::not_found

  × Not found
   ╭─[repl_entry #7:1:4]
 1 │ rm z c a
   ·    ┬
   ·    ╰── Not found
   ╰────
  help: '/tmp/z' does not exist
> 'a' | path exists
false
```

## Additional notes
- related: #15413
@github-actions github-actions Bot added this to the v0.113.0 milestone May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:commands General additions or changes to commands notes:fixes Noted in "Bug fixes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant