Skip to content

fs.writeFile mode is not Node.js compatible #3740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gutenye opened this issue Jul 22, 2023 · 2 comments · Fixed by #3747
Closed

fs.writeFile mode is not Node.js compatible #3740

gutenye opened this issue Jul 22, 2023 · 2 comments · Fixed by #3747
Labels
bug Something isn't working

Comments

@gutenye
Copy link

gutenye commented Jul 22, 2023

What version of Bun is running?

0.6.14

What platform is your computer?

No response

What steps can reproduce the bug?

import fs from 'fs'
fs.writeFileSync('a.txt', 'content', { mode: 33188 })

What is the expected behavior?

Works fine on Node

What do you see instead?

TypeError: Invalid mode: must be an octal number
code: "ERR_INVALID_ARG_TYPE"

Additional information

@gutenye gutenye added the bug Something isn't working label Jul 22, 2023
@Hanaasagi
Copy link
Collaborator

It looks like the upper limit of the value is constrained to 0o777 in bun, which is causing this issue.

bun/src/bun.js/node/types.zig

Lines 1008 to 1011 in 636cec0

if (mode_int < 0 or mode_int > 0o777) {
JSC.throwInvalidArguments("Invalid mode: must be an octal number", .{}, ctx, exception);
return null;
}

In Node.js, this limit is a u32.

https://github.com/nodejs/node/blob/9dd574c9e232515aa894795b8a2522f53024b6f7/lib/internal/validators.js#L69-L80

@Jarred-Sumner
Copy link
Collaborator

ah, we probably should wrap it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants