File tree 2 files changed +55
-2
lines changed
2 files changed +55
-2
lines changed Original file line number Diff line number Diff line change @@ -383,7 +383,10 @@ export function stat(
383
383
384
384
Deno . stat ( path ) . then (
385
385
( stat ) => callback ( null , CFISBIS ( stat , options . bigint ) ) ,
386
- ( err ) => callback ( denoErrorToNodeError ( err , { syscall : "stat" } ) ) ,
386
+ ( err ) =>
387
+ callback (
388
+ denoErrorToNodeError ( err , { syscall : "stat" , path : getPathname ( path ) } ) ,
389
+ ) ,
387
390
) ;
388
391
}
389
392
@@ -417,9 +420,16 @@ export function statSync(
417
420
return ;
418
421
}
419
422
if ( err instanceof Error ) {
420
- throw denoErrorToNodeError ( err , { syscall : "stat" } ) ;
423
+ throw denoErrorToNodeError ( err , {
424
+ syscall : "stat" ,
425
+ path : getPathname ( path ) ,
426
+ } ) ;
421
427
} else {
422
428
throw err ;
423
429
}
424
430
}
425
431
}
432
+
433
+ function getPathname ( path : string | URL ) {
434
+ return typeof path === "string" ? path : path . pathname ;
435
+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ import {
26
26
cp ,
27
27
FileHandle ,
28
28
open ,
29
+ stat ,
29
30
writeFile ,
30
31
} from "node:fs/promises" ;
31
32
import process from "node:process" ;
@@ -123,6 +124,48 @@ Deno.test(
123
124
} ,
124
125
) ;
125
126
127
+ Deno . test (
128
+ "[node/fs statSync] throw error with path information" ,
129
+ ( ) => {
130
+ const file = "non-exist-file" ;
131
+ const fileUrl = new URL ( file , import . meta. url ) ;
132
+
133
+ assertThrows ( ( ) => {
134
+ statSync ( file ) ;
135
+ } , "Error: ENOENT: no such file or directory, stat 'non-exist-file'" ) ;
136
+
137
+ assertThrows ( ( ) => {
138
+ statSync ( fileUrl ) ;
139
+ } , `Error: ENOENT: no such file or directory, stat '${ fileUrl . pathname } '` ) ;
140
+ } ,
141
+ ) ;
142
+
143
+ Deno . test (
144
+ "[node/fs/promises stat] throw error with path information" ,
145
+ async ( ) => {
146
+ const file = "non-exist-file" ;
147
+ const fileUrl = new URL ( file , import . meta. url ) ;
148
+
149
+ try {
150
+ await stat ( file ) ;
151
+ } catch ( error : unknown ) {
152
+ assertEquals (
153
+ `${ error } ` ,
154
+ "Error: ENOENT: no such file or directory, stat 'non-exist-file'" ,
155
+ ) ;
156
+ }
157
+
158
+ try {
159
+ await stat ( fileUrl ) ;
160
+ } catch ( error : unknown ) {
161
+ assertEquals (
162
+ `${ error } ` ,
163
+ `Error: ENOENT: no such file or directory, stat '${ fileUrl . pathname } '` ,
164
+ ) ;
165
+ }
166
+ } ,
167
+ ) ;
168
+
126
169
Deno . test (
127
170
"[node/fs/promises cp] copy file" ,
128
171
async ( ) => {
You can’t perform that action at this time.
0 commit comments