Skip to content

Improve error message when repository is not found #157

@batpad

Description

@batpad

Describe the bug

context
When I do for eg:

github-activity 2i2c/jupyterhub-fancy-profiles --since v0.5.2 --until v0.6.0

NOTE: the correct repo name is 2i2c-org/jupyterhub-fancy-profiles

expectation
I expected the error to tell me the repository is invalid / not found

bug
But instead, I get an error message like:

ValueError: v0.5.2 not found as a ref or valid date format

It would be nicer if it told me that the repository was not found.

✗ github-activity 2i2c/jupyterhub-fancy-profiles -s v0.5.2 -u v0.6.0
Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 771, in _get_datetime_and_type
    dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 791, in _get_datetime_from_git_ref
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.github.com/repos/2i2c/jupyterhub-fancy-profiles/commits/v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 775, in _get_datetime_and_type
    dt = dateutil.parser.parse(datetime_or_git_ref)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 643, in parse
    raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/bin/github-activity", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/cli.py", line 223, in main
    md = generate_activity_md(
        args.target,
    ...<3 lines>...
        **common_kwargs,
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 410, in generate_activity_md
    data = get_activity(
        target, since=since, until=until, kind=kind, auth=auth, cache=False
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 180, in get_activity
    since_dt, since_is_git_ref = _get_datetime_and_type(org, repo, since, auth)
                                 ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 778, in _get_datetime_and_type
    raise ValueError(
    ...<3 lines>...
    )
ValueError: v0.5.2 not found as a ref or valid date format
(env) ➜  jupyterhub-fancy-profiles git:(main) ✗ github-activity 2i2c/jupyterhub-fancy-profiles --since v0.5.2 --until v0.6.0
Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 771, in _get_datetime_and_type
    dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 791, in _get_datetime_from_git_ref
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.github.com/repos/2i2c/jupyterhub-fancy-profiles/commits/v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 775, in _get_datetime_and_type
    dt = dateutil.parser.parse(datetime_or_git_ref)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 643, in parse
    raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/bin/github-activity", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/cli.py", line 223, in main
    md = generate_activity_md(
        args.target,
    ...<3 lines>...
        **common_kwargs,
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 410, in generate_activity_md
    data = get_activity(
        target, since=since, until=until, kind=kind, auth=auth, cache=False
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 180, in get_activity
    since_dt, since_is_git_ref = _get_datetime_and_type(org, repo, since, auth)
                                 ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 778, in _get_datetime_and_type
    raise ValueError(
    ...<3 lines>...
    )
ValueError: v0.5.2 not found as a ref or valid date format
(env) ➜  jupyterhub-fancy-profiles git:(main) ✗ github-activity 2i2c/jupyterhub-fancy-profiles --since 0.5.2 --until 0.6.0
Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 771, in _get_datetime_and_type
    dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 791, in _get_datetime_from_git_ref
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.github.com/repos/2i2c/jupyterhub-fancy-profiles/commits/0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 649, in parse
    ret = self._build_naive(res, default)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 1235, in _build_naive
    naive = default.replace(**repl)
ValueError: month must be in 1..12

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 775, in _get_datetime_and_type
    dt = dateutil.parser.parse(datetime_or_git_ref)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 651, in parse
    six.raise_from(ParserError(str(e) + ": %s", timestr), e)
    ~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<string>", line 3, in raise_from
dateutil.parser._parser.ParserError: month must be in 1..12: 0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/bin/github-activity", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/cli.py", line 223, in main
    md = generate_activity_md(
        args.target,
    ...<3 lines>...
        **common_kwargs,
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 410, in generate_activity_md
    data = get_activity(
        target, since=since, until=until, kind=kind, auth=auth, cache=False
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 180, in get_activity
    since_dt, since_is_git_ref = _get_datetime_and_type(org, repo, since, auth)
                                 ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 778, in _get_datetime_and_type
    raise ValueError(
    ...<3 lines>...
    )
ValueError: 0.5.2 not found as a ref or valid date format
(env) ➜  jupyterhub-fancy-profiles git:(main) ✗ github-activity 2i2c/jupyterhub-fancy-profiles --since v0.5.2 --until v0.6.0
Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 771, in _get_datetime_and_type
    dt = _get_datetime_from_git_ref(org, repo, datetime_or_git_ref, auth)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 791, in _get_datetime_from_git_ref
    response.raise_for_status()
    ~~~~~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/requests/models.py", line 1024, in raise_for_status
    raise HTTPError(http_error_msg, response=self)
requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://api.github.com/repos/2i2c/jupyterhub-fancy-profiles/commits/v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 775, in _get_datetime_and_type
    dt = dateutil.parser.parse(datetime_or_git_ref)
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 1368, in parse
    return DEFAULTPARSER.parse(timestr, **kwargs)
           ~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/dateutil/parser/_parser.py", line 643, in parse
    raise ParserError("Unknown string format: %s", timestr)
dateutil.parser._parser.ParserError: Unknown string format: v0.5.2

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/bin/github-activity", line 8, in <module>
    sys.exit(main())
             ~~~~^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/cli.py", line 223, in main
    md = generate_activity_md(
        args.target,
    ...<3 lines>...
        **common_kwargs,
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 410, in generate_activity_md
    data = get_activity(
        target, since=since, until=until, kind=kind, auth=auth, cache=False
    )
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 180, in get_activity
    since_dt, since_is_git_ref = _get_datetime_and_type(org, repo, since, auth)
                                 ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/sanjay/seed/jupyterhub-fancy-profiles/env/lib/python3.13/site-packages/github_activity/github_activity.py", line 778, in _get_datetime_and_type
    raise ValueError(
    ...<3 lines>...
    )
ValueError: v0.5.2 not found as a ref or valid date format

problem

I seem to not be the first one to have made this mistake and a better error would have helped me see my mistake earlier.

Reproduce the bug

Run github-activity on an invalid repository name and see the output, for eg:

github-activity 2i2c/jupyterhub-fancy-profiles -s v0.5.2 -u v0.6.0

List your environment

✗ pip freeze | grep github_activity
github_activity==1.0.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions