nushell / nushell

A new type of shell
https://www.nushell.sh/
MIT License
31.61k stars 1.62k forks source link

the catch block doesn't run when script is interrupted by the user #13394

Open name-snrl opened 1 month ago

name-snrl commented 1 month ago

Describe the bug

I'm writing a script that creates a temporary directory, and I'd like the script to delete it when it terminates(no matter how). If try block terminates with an error, the directory is deleted, but if I interrupt it, nothing happens.

How to reproduce

run the script below, then interrupt it.

#!/usr/bin/env nu

let tmp = mktemp --directory
print $tmp
try {
    sleep 10sec
} catch {
    rm -rf $tmp
}
rm -rf $tmp

check the printed path directory still exists :(

Expected behavior

the directory is deleted when the script is interrupted

Screenshots

No response

Configuration

key value
version 0.92.1
branch
commit_hash
build_os linux-x86_64
build_target x86_64-unknown-linux-gnu
rust_version rustc 1.77.2 (25ef9e3d8 2024-04-09) (built from a source tarball)
cargo_version cargo 1.77.1
build_time 1980-01-01 00:00:00 +00:00
build_rust_channel release
allocator mimalloc
features default, sqlite, trash, which
installed_plugins

Additional context

No response

NotTheDr01ds commented 1 month ago

Would that be a form of a finally block?