-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Warn about async calls in .parse()
#1940
Conversation
Cherry-picked from tj#1917.
Error vs warning has been mentioned in a couple of PR. I'll explain my mental model:
|
Here is the modified model I am suggesting:
|
Actually, not sure about using an environment variable anymore because that is not something for the author to control. A probably better idea would be to introduce something like Update: Yeah, makes zero sense for a tool like |
Motivation: tj#1955
I have wondered about a warning or error for thenable in I went through all the issues mentioning For historical interest, the issues predating async support got 15 upvotes: #806 Closing for now and keep watching issues for evidence this is worthwhile. |
The warning could prevent developers like the author of the issue you linked to from neglecting It could also help forgetful developers avoid potential problems in the future when they switch to async callbacks but forget to replace But if a developer wants to insist on using
The last part is only true if a callback returns thenables in some cases and non-thenables in others, which is definitely not common. |
I was worried about some subset of commands being async. Perhaps that is unlikely, and hence less likely developer fails to notice before end-users encounter the change in behaviour. Still don't want to add it right now, but closer... |
Oh you are right, and I don't even think that's unlikely, could absolutely be the case in a program that is a collection of different utility commands, or there could be a command that does something complicated asynchronously and, at the same time, one that simply logs some static information (similar to a version command). But I do think it's unlikely the developer fails to notice the warning because they should test each command separately before making the program available to the end-user. |
Partially fixes #1916.
Cherry-picked from #1917 for better separation of concerns and because the change is the only change introduced there that can be combined meaningfully with #1938.
I would like this PR and #1938 to supersede #1917. See #1917 (comment) for details.
Why
console.warn()
and not throw from withinparse()
/parseAsync()
?Errors thrown from
parse()
/parseAsync()
are expected to have originated in user-supplied code (argParsers, hooks and actions).An alternative could be to
console.error()
andprocess.exit()
with a non-zero exit code, effectively forbidding the wrong usage, but what I don't like is the discrepancy between this approach and how all other library errors are simply thrown and can be handled by the user.ChangeLog
Added
.parse()
Peer PRs
Warnings need to be consistent with…
chainArgParserCalls()
for configuration. Additionally await thenable implicit and default option values and thenable default argument values #1915.command()
#1938Requires changes when merged with…
.suppressWarnings()
for warnings in #1915 #1931 #1938 #1940 #1955