Skip to content

rm returns directory not found error for both directories and files. #14892

Closed
@0x4D5352

Description

Describe the bug

When attempting to remove a directory that does not exist, nushell throws the error nu::shell::directory_not_found:

❯ : rm foo/
Error: nu::shell::directory_not_found

  × Directory not found
   ╭─[entry #2:1:4]
 1 │ rm foo/
   ·    ──┬─
   ·      ╰── directory not found
   ╰────
  help: /Users/mussar/workspace/github.com/0x4D5352/nushell/foo/ does not exist```

This is expected behavior. However, this same error is raised when attempting to remove a file that does not exist:

```nu
❯ : rm foo.txt
Error: nu::shell::directory_not_found

  × Directory not found
   ╭─[entry #1:1:4]
 1 │ rm foo.txt
   ·    ───┬───
   ·       ╰── directory not found
   ╰────
  help: /Users/mussar/workspace/github.com/0x4D5352/nushell/foo.txt does not exist

This might already be a tracked issue, as the code that returns this error in rm.rs is coming from a match statement on glob_from, and @cptpiepmatz is already working on updating this function: dc52a6f

How to reproduce

  1. Just try to rm a file that doesn't exist.

Expected behavior

Either return a generic error, or distinguish between directories and files.

Configuration

key value
version 0.100.0
major 0
minor 100
patch 0
branch
commit_hash
build_os macos-aarch64
build_target aarch64-apple-darwin
rust_version rustc 1.82.0 (f6e511eec 2024-10-15) (Homebrew)
cargo_version cargo 1.82.0
build_time 2024-11-13 20:37:01 -06:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins formats 0.99.1, gstat 0.99.1, highlight 1.4.1+0.100.0, inc 0.99.1, polars 0.99.1, query 0.99.1

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomersneeds-triageAn issue that hasn't had any proper lookunhelpful-errorThe error message you observe is not helpful to identify the problem

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions