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

Use different exit codes for different failures #2243

Merged
merged 11 commits into from
May 12, 2024

Conversation

ekalin
Copy link
Collaborator

@ekalin ekalin commented May 5, 2024

Fixes #2220

  • Initialization errors
  • Login errors
  • Non-fatal error while downloading
  • --abort-on
  • SIGINT / Control-C
  • Documentation

Here's the general idea of how each situation is handled:

  • Non fatal error (1): Before exiting, it is checked if something was logged to be repeated at the end (those are the real warning/erros that require attention). If so, the exit code is 1.
  • Initialization failure (2): returned by argparse for invalid options and other parsing errors; other errors that instaloader itself detects raise InvalidArgumentException, which is caught at main().
    • InvalidArgumentException is also used for other errors, that generally can only be triggered when used as a module. I don't think that's a problem, but another exception could be used specifically for those initialization errors.
  • Login failure (3): raises the new LoginException. Some more specific login exceptions were made into subclasses.
  • Download aborted (4) and user aborted (5): these were already caught at _main, it just sets a flag with the status to be returned.

Some notes:

  • I created a new exit code 99 for any uncaught InstaloaderException (at the very end of __main__.py). But maybe that except is not necessary: hopefully no exception should reach there, and if it does, maybe letting the program crash (and include the stack trace) is more appropriate.
  • I've made the failure when no IG cookies are found an actual failure. It used to just print a message and carry on (anonymously)
  • When nothing is done (no targets are specified), I'm returning non-fatal error, but initialization failure could also be appropriate, especially when the user was not logged in. But having two different status codes for two very similar situations is probably too confusing, so I used non-fatal error for both cases.

@ekalin ekalin changed the title wip: Use different exit codes for different failures Use different exit codes for different failures May 8, 2024
@ekalin
Copy link
Collaborator Author

ekalin commented May 8, 2024

I believe this is now ready for review.

Copy link
Member

@aandergr aandergr left a comment

Choose a reason for hiding this comment

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

This is an amazing change, it seems well crafted, makes our error handling cleaner and was a pleasure to go through. Thanks! I have only a few minor suggestions/remarks and then this can be merged :)

instaloader/__main__.py Outdated Show resolved Hide resolved
instaloader/__main__.py Outdated Show resolved Hide resolved
instaloader/__main__.py Outdated Show resolved Hide resolved
instaloader/instaloader.py Show resolved Hide resolved
instaloader/instaloader.py Outdated Show resolved Hide resolved
instaloader/__main__.py Outdated Show resolved Hide resolved
Exit with 2 when no target was passed and wasn't logged in, and exit
with 0 when no target was passed but was logged in (a session was saved).
@aandergr aandergr linked an issue May 12, 2024 that may be closed by this pull request
@aandergr aandergr merged commit 65b12d6 into instaloader:upcoming/v4.12 May 12, 2024
7 checks passed
@ekalin ekalin deleted the exit-codes branch May 12, 2024 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Different exit codes for different failure types
2 participants