Skip to content
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

cli: error early if --output-path is invalid #14367

Merged
merged 4 commits into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cli/cli-flags.js
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ function coerceOutput(values) {

/**
* Verifies outputPath is something we can actually write to.
* @param {unknown} value
* @param {unknown=} value
* @return {string=}
*/
function coerceOutputPath(value) {
if (value === undefined) return;

if (typeof value !== 'string' || !fs.existsSync(path.dirname(value))) {
if (typeof value !== 'string' || !value || !fs.existsSync(path.dirname(value))) {
Copy link
Member

Choose a reason for hiding this comment

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

In what situation will value === undefined.

If it's the case where --output-path is provided without any value, could we do a different error message for that?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In what situation will value === undefined.

when not provided. coerce is still called when param is not specified (or at least, it is for the "flags in a json path" case).

If it's the case where --output-path is provided without any value, could we do a different error message for that?

I think the current error is sufficient.

throw new Error(`--output-path (${value}) cannot be written to`);
}

Expand Down
2 changes: 2 additions & 0 deletions cli/test/cli/cli-flags-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,8 @@ describe('CLI flags', function() {
it('throws when path cannot be written to', () => {
expect(() => getFlags(`${url} --output-path=i/do/not/exist.json`, {noExitOnFailure: true}))
.toThrow('--output-path (i/do/not/exist.json) cannot be written to');
expect(() => getFlags(`${url} --output-path=ok.json`, {noExitOnFailure: true}))
.not.toThrow();
});
});
});
Expand Down