@@ -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 uvException ( ctx ) ;
410406 }
411407 return stats ;
412408}
@@ -1614,33 +1610,21 @@ function statfs(path, options = { bigint: false }, callback) {
16141610 binding . statfs ( pathModule . toNamespacedPath ( path ) , options . bigint , req ) ;
16151611}
16161612
1617- function hasNoEntryError ( ctx ) {
1618- if ( ctx . errno ) {
1619- const uvErr = uvErrmapGet ( ctx . errno ) ;
1620- return uvErr ?. [ 0 ] === 'ENOENT' ;
1621- }
1622-
1623- if ( ctx . error ) {
1624- return ctx . error . code === 'ENOENT' ;
1625- }
1626-
1627- return false ;
1628- }
1629-
16301613/**
16311614 * Synchronously retrieves the `fs.Stats` for
16321615 * the file descriptor.
16331616 * @param {number } fd
16341617 * @param {{
16351618 * bigint?: boolean;
16361619 * }} [options]
1637- * @returns {Stats }
1620+ * @returns {Stats | undefined }
16381621 */
16391622function fstatSync ( fd , options = { bigint : false } ) {
16401623 fd = getValidatedFd ( fd ) ;
1641- const ctx = { fd } ;
1642- const stats = binding . fstat ( fd , options . bigint , undefined , ctx ) ;
1643- handleErrorFromBinding ( ctx ) ;
1624+ const stats = binding . fstat ( fd , options . bigint , undefined , false ) ;
1625+ if ( stats === undefined ) {
1626+ return ;
1627+ }
16441628 return getStatsFromBinding ( stats ) ;
16451629}
16461630
@@ -1652,17 +1636,20 @@ function fstatSync(fd, options = { bigint: false }) {
16521636 * bigint?: boolean;
16531637 * throwIfNoEntry?: boolean;
16541638 * }} [options]
1655- * @returns {Stats }
1639+ * @returns {Stats | undefined }
16561640 */
16571641function lstatSync ( path , options = { bigint : false , throwIfNoEntry : true } ) {
16581642 path = getValidatedPath ( path ) ;
1659- const ctx = { path } ;
1660- const stats = binding . lstat ( pathModule . toNamespacedPath ( path ) ,
1661- options . bigint , undefined , ctx ) ;
1662- if ( options . throwIfNoEntry === false && hasNoEntryError ( ctx ) ) {
1663- return undefined ;
1643+ const stats = binding . lstat (
1644+ pathModule . toNamespacedPath ( path ) ,
1645+ options . bigint ,
1646+ undefined ,
1647+ options . throwIfNoEntry ,
1648+ ) ;
1649+
1650+ if ( stats === undefined ) {
1651+ return ;
16641652 }
1665- handleErrorFromBinding ( ctx ) ;
16661653 return getStatsFromBinding ( stats ) ;
16671654}
16681655
@@ -2665,9 +2652,10 @@ function realpathSync(p, options) {
26652652
26662653 // On windows, check that the root exists. On unix there is no need.
26672654 if ( isWindows ) {
2668- const ctx = { path : base } ;
2669- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2670- handleErrorFromBinding ( ctx ) ;
2655+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2656+ if ( out === undefined ) {
2657+ return ;
2658+ }
26712659 knownHard . add ( base ) ;
26722660 }
26732661
@@ -2707,9 +2695,10 @@ function realpathSync(p, options) {
27072695 // for our internal use.
27082696
27092697 const baseLong = pathModule . toNamespacedPath ( base ) ;
2710- const ctx = { path : base } ;
2711- const stats = binding . lstat ( baseLong , true , undefined , ctx ) ;
2712- handleErrorFromBinding ( ctx ) ;
2698+ const stats = binding . lstat ( baseLong , true , undefined , true /* throwIfNoEntry */ ) ;
2699+ if ( stats === undefined ) {
2700+ return ;
2701+ }
27132702
27142703 if ( ! isFileType ( stats , S_IFLNK ) ) {
27152704 knownHard . add ( base ) ;
@@ -2748,9 +2737,10 @@ function realpathSync(p, options) {
27482737
27492738 // On windows, check that the root exists. On unix there is no need.
27502739 if ( isWindows && ! knownHard . has ( base ) ) {
2751- const ctx = { path : base } ;
2752- binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , ctx ) ;
2753- handleErrorFromBinding ( ctx ) ;
2740+ const out = binding . lstat ( pathModule . toNamespacedPath ( base ) , false , undefined , true /* throwIfNoEntry */ ) ;
2741+ if ( out === undefined ) {
2742+ return ;
2743+ }
27542744 knownHard . add ( base ) ;
27552745 }
27562746 }
0 commit comments