Since version 10, function like fs.chmod()
or fs.mkdir()
check if their mode
parameter is below o777
throwing a RangeError exception if the condition isn't satisfied.
This requirement is too strict as the mode parameter can often be above o777
if it need to set the S_ISUID
or S_ISGID
bits.
Furthermore this range check break several node packages (e.g. graceful-fs
used by over 1400 other packages) in a very common scenario:
A program wants to create a new file/directory with the same rights that a reference file/directory. Often the mode
attribute of fs.Stats
object is directly passed to fs.chmod()
or fs.mkdir()
. However the fs.Stats.mode
is always above o777
(e.g. o100644
) since it also contains the file type bits.
Classic POSIX version of chmod
or mkdir
seems to handle those kind a values without complaining by discarding the irrelevant bits instead of throwing an error. Why do Node need to be so brutal about it?
Seeing the same issue here. Breaking graceful-fs
actually breaks vinyl-fs
, so it actually breaks gulp
(yes, even gulp@4
).
In my case, I only see the issue when running on CI...
cc @targos @BridgeAR We discussed about unifying this check in https://github.com/nodejs/node/pull/19973#pullrequestreview-114305956 I am leaning towards masking off the relevant bits since that's what the underlying POSIX API usually does.
Also cc @jasnell the check is added in https://github.com/nodejs/node/pull/17334
I'm good with masking off the bits and relaxing the check :)
Also, it's obvious we don't have good test coverage for this particular case so it would be good to expand that a bit.
I also agree that masking off seems the right thing to do.
Hi,
I just wanted to mention that I also encountered this bug. It happens when I use Gulp (graceful-fs) on Gitlab CI:
RangeError [ERR_OUT_OF_RANGE]: The value of "mode" is out of range. Received 33206
at Object.fs.fchmod (fs.js:1024:11)
at Object.fchmod (/builds/demurgos/node-devkit/node_modules/graceful-fs/polyfills.js:237:17)
at mode (/builds/demurgos/node-devkit/node_modules/vinyl-fs/lib/file-operations.js:237:10)
at onStat (/builds/demurgos/node-devkit/node_modules/vinyl-fs/lib/file-operations.js:227:14)
at /builds/demurgos/node-devkit/node_modules/graceful-fs/polyfills.js:287:18
at FSReqWrap.oncomplete (fs.js:150:5)
I'm having the same issue above with Gulp 4(graceful-fs) in my local build. What can I do to fix this?
same here.
graceful-fs's RangeError [ERR_OUT_OF_RANGE] solved by #20588.
Great work. Thanks!
Is it supposed to be fixed in 10.3.0
? Still have this issue there
RangeError [ERR_OUT_OF_RANGE]: The value of "mode" is out of range. Received 33204
at Object.fs.fchmod (fs.js:1056:11)
at Object.fchmod (/workspace/node_modules/graceful-fs/polyfills.js:237:17)
at mode (/workspace/node_modules/vinyl-fs/lib/file-operations.js:237:10)
at onStat (/workspace/node_modules/vinyl-fs/lib/file-operations.js:227:14)
at /workspace/node_modules/graceful-fs/polyfills.js:287:18
at FSReqWrap.oncomplete (fs.js:183:5)
@klimashkin https://github.com/nodejs/node/pull/20636 has not been backported to v10 (will be backported with https://github.com/nodejs/node/pull/20975)
Really disappointing to hear @joyeecheung.
As an Arch user I just held back Node so I could work on Gulp-based projects while this was resolving itself -- but now that 10.3 has been released via Homebrew the first thing on tomorrow's agenda will be alerting devs company wide to delay upgrading Node.
Will the first release with these fixes be in a backported minor release or should we be waiting for the next major release? Regardless, thank you Node team for all the work and effort!
When it will be in master? 10.4.1 released but still
RangeError [ERR_OUT_OF_RANGE]: The value of "mode" is out of range. Received 33206
at Object.fs.fchmod (fs.js:1058:11)
@Delagen It's on v10.x-staging now, should be available in the next release.
@joyeecheung This was broken for about 7 releases of 10.x branch. Speed of fixes make me sad (
Comments like yours make me sad. It adds nothing except another notification email to 100+ people.
Most helpful comment
Comments like yours make me sad. It adds nothing except another notification email to 100+ people.