@@ -74,8 +74,6 @@ const {
7474 ERR_INVALID_ARG_VALUE ,
7575 } ,
7676 AbortError,
77- uvErrmapGet,
78- UVException,
7977} = require ( 'internal/errors' ) ;
8078
8179const {
@@ -402,11 +400,9 @@ function readFile(path, options, callback) {
402400}
403401
404402function tryStatSync ( fd , isUserFd ) {
405- const ctx = { } ;
406- const stats = binding . fstat ( fd , false , undefined , ctx ) ;
407- if ( ctx . errno !== undefined && ! isUserFd ) {
403+ const stats = binding . fstat ( fd , false , undefined , true /* shouldNotThrow */ ) ;
404+ if ( stats === undefined && ! isUserFd ) {
408405 fs . closeSync ( fd ) ;
409- throw new UVException ( ctx ) ;
410406 }
411407 return stats ;
412408}
@@ -1616,33 +1612,21 @@ function statfs(path, options = { bigint: false }, callback) {
16161612 binding . statfs ( pathModule . toNamespacedPath ( path ) , options . bigint , req ) ;
16171613}
16181614
1619- function hasNoEntryError ( ctx ) {
1620- if ( ctx . errno ) {
1621- const uvErr = uvErrmapGet ( ctx . errno ) ;
1622- return uvErr ?. [ 0 ] === 'ENOENT' ;
1623- }
1624-
1625- if ( ctx . error ) {
1626- return ctx . error . code === 'ENOENT' ;
1627- }
1628-
1629- return false ;
1630- }
1631-
16321615/**
16331616 * Synchronously retrieves the `fs.Stats` for
16341617 * the file descriptor.
16351618 * @param {number } fd
16361619 * @param {{
16371620 * bigint?: boolean;
16381621 * }} [options]
1639- * @returns {Stats }
1622+ * @returns {Stats | undefined }
16401623 */
16411624function fstatSync ( fd , options = { bigint : false } ) {
16421625 fd = getValidatedFd ( fd ) ;
1643- const ctx = { fd } ;
1644- const stats = binding . fstat ( fd , options . bigint , undefined , ctx ) ;
1645- handleErrorFromBinding ( ctx ) ;
1626+ const stats = binding . fstat ( fd , options . bigint , undefined , false ) ;
1627+ if ( stats === undefined ) {
1628+ return ;
1629+ }
16461630 return getStatsFromBinding ( stats ) ;
16471631}
16481632
@@ -1654,17 +1638,20 @@ function fstatSync(fd, options = { bigint: false }) {
16541638 * bigint?: boolean;
16551639 * throwIfNoEntry?: boolean;
16561640 * }} [options]
1657- * @returns {Stats }
1641+ * @returns {Stats | undefined }
16581642 */
16591643function lstatSync ( path , options = { bigint : false , throwIfNoEntry : true } ) {
16601644 path = getValidatedPath ( path ) ;
1661- const ctx = { path } ;
1662- const stats = binding . lstat ( pathModule . toNamespacedPath ( path ) ,
1663- options . bigint , undefined , ctx ) ;
1664- if ( options . throwIfNoEntry === false && hasNoEntryError ( ctx ) ) {
1665- return undefined ;
1645+ const stats = binding . lstat (
1646+ pathModule . toNamespacedPath ( path ) ,
1647+ options . bigint ,
1648+ undefined ,
1649+ options . throwIfNoEntry ,
1650+ ) ;
1651+
1652+ if ( stats === undefined ) {
1653+ return ;
16661654 }
1667- handleErrorFromBinding ( ctx ) ;
16681655 return getStatsFromBinding ( stats ) ;
16691656}
16701657
@@ -2667,9 +2654,10 @@ function realpathSync(p, options) {
26672654
26682655 // On windows, check that the root exists. On unix there is no need.
26692656 if ( isWindows ) {
2670- const ctx = { path : base } ;
2671- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2672- handleErrorFromBinding ( ctx ) ;
2657+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2658+ if ( out === undefined ) {
2659+ return ;
2660+ }
26732661 knownHard . add ( base ) ;
26742662 }
26752663
@@ -2709,9 +2697,10 @@ function realpathSync(p, options) {
27092697 // for our internal use.
27102698
27112699 const baseLong = pathModule . toNamespacedPath ( base ) ;
2712- const ctx = { path : base } ;
2713- const stats = binding . lstat ( baseLong , true , undefined , ctx ) ;
2714- handleErrorFromBinding ( ctx ) ;
2700+ const stats = binding . lstat ( baseLong , true , undefined , true /* throwIfNoEntry */ ) ;
2701+ if ( stats === undefined ) {
2702+ return ;
2703+ }
27152704
27162705 if ( ! isFileType ( stats , S_IFLNK ) ) {
27172706 knownHard . add ( base ) ;
@@ -2750,9 +2739,10 @@ function realpathSync(p, options) {
27502739
27512740 // On windows, check that the root exists. On unix there is no need.
27522741 if ( isWindows && ! knownHard . has ( base ) ) {
2753- const ctx = { path : base } ;
2754- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2755- handleErrorFromBinding ( ctx ) ;
2742+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2743+ if ( out === undefined ) {
2744+ return ;
2745+ }
27562746 knownHard . add ( base ) ;
27572747 }
27582748 }
0 commit comments