-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Different exit codes for different failure types #2220
Comments
Yes, this would be a nice feature. I was wondering whether there was some kind of standard or convention for how exit codes are assigned in typical unix applications, but it seems there is none except of zero being a success status and non-zero an error status. Apart of that, all tools seem to follow their arbitrary mapping of error types to exit codes. Instaloader already distinguishes many types of errors with different exception types, it would be great to map those into return codes for the cli application. We could somehow resemble the exception tree, combined with some semantical/logical grouping of error types into the error code, e.g. by assigning a few bits to the group and the other bits to a finer granulation, as this might simplify the parsing of the exit status. So we would both have a fine granularity without making the feature less useful I think. I could imagine something like
So this would imply a grouping of
This is close to the grouping given by the exception tree, which itself was built on the way of how they must be handled internally. However, this is only a suggestion after brief consideration. I do not want to rule out the possibility that there might be a more sensible or appropriate mapping. |
I think too many exit codes would actually add too much complexity for little benefit. If the user needs that much detail, they can use instaloader as a module and catch the actual exceptions. [Moreover, retrofitting the exit codes in the existing code is not trivial - and the more different codes there are, the more work is necessary.] But in addition to the general categories I had identified, some of the ones you listed can be useful:
Basically your idea of groups is quite similar to my proposal, but I'm not really convinced that the level of detail provided by the lower byte is really useful. And from what I remember, some errors you listed ("bad request", "forbidden", etc) don't cause the program to terminate, just to retry or skip that item. |
I think, this is a very convincing point. I also agree that my suggested mapping from exceptions to error codes is not at all practical as is, since almost all exceptions are handled internally and do not directly lead to a termination.
If one of many profiles have failed, Instaloader should probably return a non-zero exit code to indicate there was a failure. This however means that multiple different failures may have happened (and handled) during the download loop, narrowing down the number of exit codes that we can return. All in all it seems we might agree on the following return codes:
|
This set of codes looks good, but I'd like to propose a small change: 0 Finished normally The reason is that Since what was proposed as exit code 3 can be a non-fatal error (one profile failed, but other might have succeeded), I think it's a good fit for error code 1. Alternatively, we could just one use exit code 1, there's nothing saying the error codes have to be sequential and that all values must be used. |
Provide us a use case of the feature
I believe instaloader should exit with a non-zero exit code in case of failure. This has been requested already (#1614) and there is even a PR for this (#2166). However, I believe that not only a non-zero exit code should be used, but different codes should be used for different failures.
Describe the solution you'd like
I thought of something like
0 - Finished normally
1 - Initialization failure: invalid command line arguments, --load-cookies without the library, and other failures before anything was attempted
2 - Login failure
3 - Failure while downloading
4 - User aborted (I'm not sure if this is an error - after all, the user requested the action. But it might be useful to distinguish this case)
Maybe there could be a couple more situations. But too much granularity might make this feature less useful.
Describe alternatives you've considered
There really aren't many alternatives. One can try parsing the output, but there are too many possible error messages.
If the feature request is accepted, would you be willing to submit a pull request?
Yes
The text was updated successfully, but these errors were encountered: