mirror of
https://github.com/denoland/deno.git
synced 2024-11-24 15:19:26 -05:00
fix(core): don't panic on non-existent cwd (#14957)
Co-authored-by: cjihrig <cjihrig@gmail.com>
This commit is contained in:
parent
fd5a12d7e2
commit
18c9a7ad64
3 changed files with 37 additions and 2 deletions
|
@ -602,7 +602,7 @@ async fn eval_command(
|
|||
// deno_graph works off of extensions for local files to determine the media
|
||||
// type, and so our "fake" specifier needs to have the proper extension.
|
||||
let main_module =
|
||||
resolve_url_or_path(&format!("./$deno$eval.{}", eval_flags.ext)).unwrap();
|
||||
resolve_url_or_path(&format!("./$deno$eval.{}", eval_flags.ext))?;
|
||||
let permissions = Permissions::from_options(&flags.permissions_options());
|
||||
let ps = ProcState::build(Arc::new(flags)).await?;
|
||||
let mut worker = create_main_worker(
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import {
|
||||
assert,
|
||||
assertEquals,
|
||||
assertStrictEquals,
|
||||
assertStringIncludes,
|
||||
assertThrows,
|
||||
} from "./test_util.ts";
|
||||
|
@ -628,3 +629,35 @@ Deno.test(
|
|||
}
|
||||
},
|
||||
);
|
||||
|
||||
Deno.test(
|
||||
{
|
||||
permissions: { run: true, read: true, write: true },
|
||||
ignore: Deno.build.os === "windows",
|
||||
},
|
||||
async function non_existent_cwd(): Promise<void> {
|
||||
const p = Deno.run({
|
||||
cmd: [
|
||||
Deno.execPath(),
|
||||
"eval",
|
||||
`const dir = Deno.makeTempDirSync();
|
||||
Deno.chdir(dir);
|
||||
Deno.removeSync(dir);
|
||||
const p = Deno.run({cmd:[Deno.execPath(), "eval", "console.log(1);"]});
|
||||
const { code } = await p.status();
|
||||
p.close();
|
||||
Deno.exit(code);
|
||||
`,
|
||||
],
|
||||
stdout: "piped",
|
||||
stderr: "piped",
|
||||
});
|
||||
|
||||
const { code } = await p.status();
|
||||
const stderr = new TextDecoder().decode(await p.stderrOutput());
|
||||
p.close();
|
||||
p.stdout.close();
|
||||
assertStrictEquals(code, 1);
|
||||
assertStringIncludes(stderr, "invalid module path");
|
||||
},
|
||||
);
|
||||
|
|
|
@ -138,7 +138,9 @@ pub fn resolve_url_or_path(
|
|||
pub fn resolve_path(
|
||||
path_str: &str,
|
||||
) -> Result<ModuleSpecifier, ModuleResolutionError> {
|
||||
let path = current_dir().unwrap().join(path_str);
|
||||
let path = current_dir()
|
||||
.map_err(|_| ModuleResolutionError::InvalidPath(path_str.into()))?
|
||||
.join(path_str);
|
||||
let path = normalize_path(&path);
|
||||
Url::from_file_path(path.clone())
|
||||
.map_err(|()| ModuleResolutionError::InvalidPath(path))
|
||||
|
|
Loading…
Reference in a new issue