fs: improve error message for invalid flag by jasnell · Pull Request #5590 · nodejs/node (original) (raw)

jasnell

Pull Request check-list

Affected core subsystem(s)

fs

Description of change

Flags on fs.open and others can be passed as strings or int.
Previously, if passing anything other than string or int,
the error message would only say that flags must be an int.

@jasnell jasnell added fs

Issues and PRs related to the fs subsystem / file system.

semver-major

PRs that contain breaking changes and should be released in the next major version.

error-handling labels

Mar 7, 2016

@jasnell

This one isn't obvious... basically, by changing the early out condition on stringToFlag it falls through to the error that is reported if the string flag is not correct.

@cjihrig

@jasnell

@jasnell

@cjihrig

@jasnell

@jasnell

Ok, looks like something is borked with the OSX build bot (cc @nodejs/build). Otherwise this looks ok. Tests pass locally on OSX. Given that this is a major, I'll give it until tomorrow or Wednesday to land.

@jasnell

@MylesBorins

bnoordhuis

assert.throws(
() => fs._stringToFlags({}),
(err) => /^Unknown file open flag: \[object Object\]/.test(err.message)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can shorten this to just the regex, i.e.:

assert.throws( () => fs._stringToFlags({}), /^Unknown file open flag: [object Object]/);

@bnoordhuis

@jasnell

Flags on fs.open and others can be passed as strings or int. Previously, if passing anything other than string or int, the error message would only say that flags must be an int.

@jasnell

jasnell added a commit that referenced this pull request

Mar 9, 2016

@jasnell

Flags on fs.open and others can be passed as strings or int. Previously, if passing anything other than string or int, the error message would only say that flags must be an int.

PR-URL: #5590 Reviewed-By: Colin Ihrig cjihrig@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ben Noordhuis info@bnoordhuis.nl

jasnell added a commit that referenced this pull request

Mar 9, 2016

@jasnell

PR-URL: #5590 Reviewed-By: Colin Ihrig cjihrig@gmail.com Reviewed-By: Myles Borins myles.borins@gmail.com Reviewed-By: Ben Noordhuis info@bnoordhuis.nl

@jasnell

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.

jasnell added a commit that referenced this pull request

Apr 26, 2016

@jasnell

The following significant (semver-major) changes have been made since the previous Node v5.0.0 release.