mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
fix(ext/node): add path to fs.stat
and fs.statSync
error (#26037)
This commit is contained in:
parent
05868cc236
commit
c314b2d857
2 changed files with 55 additions and 2 deletions
|
@ -383,7 +383,10 @@ export function stat(
|
||||||
|
|
||||||
Deno.stat(path).then(
|
Deno.stat(path).then(
|
||||||
(stat) => callback(null, CFISBIS(stat, options.bigint)),
|
(stat) => callback(null, CFISBIS(stat, options.bigint)),
|
||||||
(err) => callback(denoErrorToNodeError(err, { syscall: "stat" })),
|
(err) =>
|
||||||
|
callback(
|
||||||
|
denoErrorToNodeError(err, { syscall: "stat", path: getPathname(path) }),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -417,9 +420,16 @@ export function statSync(
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (err instanceof Error) {
|
if (err instanceof Error) {
|
||||||
throw denoErrorToNodeError(err, { syscall: "stat" });
|
throw denoErrorToNodeError(err, {
|
||||||
|
syscall: "stat",
|
||||||
|
path: getPathname(path),
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getPathname(path: string | URL) {
|
||||||
|
return typeof path === "string" ? path : path.pathname;
|
||||||
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import {
|
||||||
cp,
|
cp,
|
||||||
FileHandle,
|
FileHandle,
|
||||||
open,
|
open,
|
||||||
|
stat,
|
||||||
writeFile,
|
writeFile,
|
||||||
} from "node:fs/promises";
|
} from "node:fs/promises";
|
||||||
import process from "node:process";
|
import process from "node:process";
|
||||||
|
@ -123,6 +124,48 @@ Deno.test(
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"[node/fs statSync] throw error with path information",
|
||||||
|
() => {
|
||||||
|
const file = "non-exist-file";
|
||||||
|
const fileUrl = new URL(file, import.meta.url);
|
||||||
|
|
||||||
|
assertThrows(() => {
|
||||||
|
statSync(file);
|
||||||
|
}, "Error: ENOENT: no such file or directory, stat 'non-exist-file'");
|
||||||
|
|
||||||
|
assertThrows(() => {
|
||||||
|
statSync(fileUrl);
|
||||||
|
}, `Error: ENOENT: no such file or directory, stat '${fileUrl.pathname}'`);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
Deno.test(
|
||||||
|
"[node/fs/promises stat] throw error with path information",
|
||||||
|
async () => {
|
||||||
|
const file = "non-exist-file";
|
||||||
|
const fileUrl = new URL(file, import.meta.url);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await stat(file);
|
||||||
|
} catch (error: unknown) {
|
||||||
|
assertEquals(
|
||||||
|
`${error}`,
|
||||||
|
"Error: ENOENT: no such file or directory, stat 'non-exist-file'",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await stat(fileUrl);
|
||||||
|
} catch (error: unknown) {
|
||||||
|
assertEquals(
|
||||||
|
`${error}`,
|
||||||
|
`Error: ENOENT: no such file or directory, stat '${fileUrl.pathname}'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
Deno.test(
|
Deno.test(
|
||||||
"[node/fs/promises cp] copy file",
|
"[node/fs/promises cp] copy file",
|
||||||
async () => {
|
async () => {
|
||||||
|
|
Loading…
Reference in a new issue