Skip to content

Turn GitHub API errors into exceptions #21

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

Closed
simonw opened this issue Mar 23, 2020 · 2 comments
Closed

Turn GitHub API errors into exceptions #21

simonw opened this issue Mar 23, 2020 · 2 comments
Labels
enhancement New feature or request
Milestone

Comments

@simonw
Copy link
Collaborator

simonw commented Mar 23, 2020

This would have really helped in debugging the mess in #13. Running with this auth.json is a useful demo:

{"github_personal_token": ""}
@simonw simonw added the enhancement New feature or request label Mar 23, 2020
@simonw simonw added this to the 1.0 milestone Mar 23, 2020
@simonw
Copy link
Collaborator Author

simonw commented Mar 23, 2020

I'm going to do this now to help figure out the latest error in #13:

Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.8.2/x64/bin/github-to-sqlite", line 11, in <module>
    load_entry_point('github-to-sqlite', 'console_scripts', 'github-to-sqlite')()
  File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/click/core.py", line 829, in __call__
    return self.main(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/click/core.py", line 782, in main
    rv = self.invoke(ctx)
  File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/opt/hostedtoolcache/Python/3.8.2/x64/lib/python3.8/site-packages/click/core.py", line 610, in invoke
    return callback(*args, **kwargs)
  File "/home/runner/work/github-to-sqlite/github-to-sqlite/github_to_sqlite/cli.py", line 237, in commits
    utils.save_commits(db, commits, repo_full["id"])
  File "/home/runner/work/github-to-sqlite/github-to-sqlite/github_to_sqlite/utils.py", line 345, in save_commits
    for commit in commits:
  File "/home/runner/work/github-to-sqlite/github-to-sqlite/github_to_sqlite/utils.py", line 207, in fetch_commits
    if stop_when(commit):
  File "/home/runner/work/github-to-sqlite/github-to-sqlite/github_to_sqlite/cli.py", line 224, in stop_when
    db["commits"].get(commit["sha"])
TypeError: string indices must be integers

simonw added a commit that referenced this issue Mar 23, 2020
@simonw
Copy link
Collaborator Author

simonw commented Mar 23, 2020

I'm happy with this pattern:

class GitHubError(Exception):
def __init__(self, message, status_code):
self.message = message
self.status_code = status_code
@classmethod
def from_response(cls, response):
message = response.json()["message"]
if "git repository is empty" in message.lower():
cls = GitHubRepositoryEmpty
return cls(message, response.status_code)
class GitHubRepositoryEmpty(GitHubError):
pass

@simonw simonw closed this as completed Mar 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant