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

Print the "invalid value" for output in CLI flags #12787

Closed
2 tasks done
ha-douken opened this issue Jul 14, 2021 · 5 comments
Closed
2 tasks done

Print the "invalid value" for output in CLI flags #12787

ha-douken opened this issue Jul 14, 2021 · 5 comments

Comments

@ha-douken
Copy link

FAQ

URL

https://www.google.com

What happened?

$ npx lighthouse --output=json --output=html https://www.google.com
throws
Invalid values. Argument 'output' must be an array from choices "json", "html", "csv"

node: v12.22.3
"lighthouse": "8.1.0"

What did you expect?

It to run.

What have you tried?

No response

How were you running Lighthouse?

CLI

Lighthouse Version

8.1.0

Chrome Version

No response

Node Version

12.22.3

Relevant log output

Invalid values. Argument 'output' must be an array from choices "json", "html", "csv"
@patrickhulce
Copy link
Collaborator

Thanks for filing @ha-douken! This is unfortunately, WAI. --output is flexible so it allows the use of spaces in between arguments. You need to run npx lighthouse https://www.google.com --output=json --output=html. As a rule, always put the URL first.

The error message could definitely be improved though, we'll add the unexpected value to the debug output.

@patrickhulce patrickhulce changed the title lighthouse-cli throws Invalid values. Argument 'output' must be an array from choices "json", "html", "csv" Print the "invalid value" for output in CLI flags Jul 14, 2021
@svkrclg
Copy link
Contributor

svkrclg commented Jul 28, 2021

Is this issue being picked up for dev? If not, would love to work on this. Any directions would be awesome @patrickhulce

@patrickhulce
Copy link
Collaborator

Go for it @svkrclg!

Basically in

const outputTypes = ['json', 'html', 'csv'];
const errorMsg = `Invalid values. Argument 'output' must be an array from choices "${outputTypes.join('", "')}"`;
if (!values.every(/** @return {item is string} */ item => typeof item === 'string')) {
throw new Error(errorMsg);
}
// Allow parsing of comma-separated values.
const strings = values.flatMap(value => value.split(','));
if (!strings.every(/** @return {str is LH.OutputMode} */ str => outputTypes.includes(str))) {
throw new Error(errorMsg);
}
return strings;

you'll want to add the value that failed validation to our error message instead of just a generic one :)

@rohan-kulkarni-25
Copy link

Hey @patrickhulce Is this issue solved or needs any more help !! Please let me know I will be happy to do

@patrickhulce
Copy link
Collaborator

This has been solved by #12836, thanks @rohan-kulkarni-25!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants