Skip to content

rm command does not throw when removing file in use #14900

Open
@bminer

Description

Describe the bug

When wrapping rm in a try / catch block, sometimes it does strange things. If the file is in use when deleted on Windows, the try following snippet would print "success" instead of "fail".

try { rm web.exe; "success" } catch { "fail" }

How to reproduce

  1. Run nushell on Windows
  2. Make sure the file you are trying to delete is in use
  3. Run the command as follows:
try { rm web.exe; "success" } catch { "fail" }

Output:

Error: nu::shell::remove_not_possible

  × Remove not possible
   ╭─[entry #16:2:4]
 1 │ try {
 2 │ rm web.exe;
   ·    ───┬───
   ·       ╰── Could not delete C:\Users\[REDACTED]\web.exe: Access is denied. (os error 5)
 3 │ "success"
   ╰────

success

(note that the error is printed followed by "success")

Expected behavior

Expected rm to throw an error and invoke the catch block, printing "fail" instead.

Configuration

key value
version 0.101.0
major 0
minor 101
patch 0
branch
commit_hash fb26109
build_os windows-x86_64
build_target x86_64-pc-windows-msvc
rust_version rustc 1.81.0 (eeb90cda1 2024-09-04)
rust_channel 1.81.0-x86_64-pc-windows-msvc
cargo_version cargo 1.81.0 (2dbb1af80 2024-08-20)
build_time 2024-12-22 15:52:47 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash
installed_plugins query 0.100.0

Metadata

Assignees

No one assigned

    Labels

    error-handlingHow errors in externals/nu code are caught or handled programmatically (see also unhelpful-error)file-systemRelated to commands and core nushell behavior around the file systemneeds-triageAn issue that hasn't had any proper look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions