deno icon indicating copy to clipboard operation
deno copied to clipboard

`deno test` panics when removing the directory that you're in

Open jespertheend opened this issue 3 years ago • 3 comments

Possibly a duplicate of #13737 but for some reason I'm only getting a panic when running this in a test, so I think it might be a separate issue. The backtrace also seems different.

  1. Download and cd into panic.zip
  2. Run deno test -A
RUST_BACKTRACE=full deno test -A
running 1 test from ./createDir.test.js
mkdir ... ok (9ms)

============================================================
Deno has panicked. This is a bug in Deno. Please report this
at https://github.com/denoland/deno/issues/new.
If you can reliably reproduce this panic, include the
reproduction steps and re-run with the RUST_BACKTRACE=1 env
var set and include the backtrace in your report.

Platform: macos x86_64
Version: 1.25.2+a54d565
Args: ["deno", "test", "-A"]

thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: InvalidPath(".")', cli/proc_state.rs:557:48
stack backtrace:
   0:        0x1076f4a49 - <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt::h85521558a183f368
   1:        0x106c4499b - core::fmt::write::h01631fae0d2b98bc
   2:        0x1076c5658 - std::io::Write::write_fmt::h675dde99a2999169
   3:        0x1076f983d - std::panicking::default_hook::{{closure}}::h5e5df492d229fd65
   4:        0x1076f9524 - std::panicking::default_hook::h18647b59f1a84ee2
   5:        0x106bb3c03 - deno::setup_panic_hook::{{closure}}::hd98d30ee0fd9ec8a
   6:        0x1076fa38b - std::panicking::rust_panic_with_hook::hd9ead35a68ccc55e
   7:        0x1076fa204 - std::panicking::begin_panic_handler::{{closure}}::h6fca91c5e1dc2f30
   8:        0x1076fa179 - std::sys_common::backtrace::__rust_end_short_backtrace::h4ff3025d9a0a0490
   9:        0x1076fa135 - _rust_begin_unwind
  10:        0x108aa6573 - core::panicking::panic_fmt::h3d9f795ee387ef8d
  11:        0x108aa67d5 - core::result::unwrap_failed::haca1aa19e4c34aab
  12:        0x10691b9c7 - core::result::Result<T,E>::unwrap::hfbc042446b6f9975
  13:        0x106b54e99 - <deno::module_loader::CliModuleLoader as deno_core::modules::ModuleLoader>::resolve::h89be496a7b4bf85b
  14:        0x106d3b170 - deno_core::modules::RecursiveModuleLoad::resolve_root::h8866a4e10c3803cf
  15:        0x106d3905a - deno_core::modules::RecursiveModuleLoad::new::h18365cc75b396750
  16:        0x106a1019c - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h406ed18d1bc05ca5
  17:        0x106a075e3 - <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll::h2fa57802fb66b018
  18:        0x10695600b - tokio::runtime::task::raw::poll::h431dd3c0509443a5
  19:        0x107866be2 - std::sys_common::backtrace::__rust_begin_short_backtrace::h13e1d090678f02ea
  20:        0x107866992 - core::ops::function::FnOnce::call_once{{vtable.shim}}::hfc07edbde7ee2710
  21:        0x1076fcd89 - std::sys::unix::thread::Thread::new::thread_start::hf7c5ae502e9a7ed8
  22:     0x7ff81aea84e1 - __pthread_start

What's weird is that if I remove the other (empty) test file, the panic no longer happens.

Here are the contents of createDir.test.js:

import { resolve } from "https://deno.land/[email protected]/path/mod.ts";

Deno.test({
	name: "mkdir",
	async fn() {
		const dir = resolve("dir");
		await Deno.mkdir(dir);

		Deno.chdir(dir);

		await Deno.writeTextFile("file.txt", "hello");
		await Deno.remove(dir, { recursive: true });
	},
});

jespertheend avatar Sep 10 '22 14:09 jespertheend

So I did a bit of digging into this. I'm not entirely sure what the expected behavior is.

If the current directory deno is pointing at is removed should it default to just go up one directory?

brenelz avatar Sep 11 '22 01:09 brenelz

On ubuntu the cwd stays as is, but if you try to perform any actions such as creating a file in the cwd you'll get an error. Not sure about any other platforms.

jespertheend avatar Sep 11 '22 02:09 jespertheend

Basically the rust code is panicking when it tries to get the current_dir()

brenelz avatar Sep 11 '22 02:09 brenelz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Nov 12 '22 05:11 stale[bot]

I can still reproduce this in Deno 1.27.2

jespertheend avatar Nov 12 '22 11:11 jespertheend