Skip to content

fix: skip empty repositories instead of crashing#591

Open
wjglerum wants to merge 1 commit into
github-community-projects:mainfrom
wjglerum:fix/empty-repo-404
Open

fix: skip empty repositories instead of crashing#591
wjglerum wants to merge 1 commit into
github-community-projects:mainfrom
wjglerum:fix/empty-repo-404

Conversation

@wjglerum

@wjglerum wjglerum commented Jul 6, 2026

Copy link
Copy Markdown

Problem

When Evergreen iterates over an organization that contains an empty repository (one created but never pushed to, so it has no commits), the run crashes:

github.GithubException.GithubException: This repository is empty.: 404
{"message": "This repository is empty.",
 "documentation_url": "https://docs.github.com/v3/repos/contents/#get-contents",
 "status": "404"}

check_optional_file() in exceptions.py calls repo.get_contents(...) to look for an existing dependabot.yml. For a repo where the file merely does not exist, PyGithub raises UnknownObjectException, which is caught and translated to OptionalFileNotFoundError. But for an empty repository, GitHub returns a 404 that PyGithub surfaces as the base GithubException ("This repository is empty."), not UnknownObjectException. That escapes the existing handler and aborts the whole run, so no other repositories in the org get processed.

Fix

Handle a 404 GithubException the same way as a missing optional file, so the repository is treated as having no config and skipped by the normal flow. Non-404 GithubExceptions (permissions, rate limits, server errors) are re-raised unchanged so genuine problems are not masked.

Tests

Added two cases to test_exceptions.py:

  • an empty-repository 404 (base GithubException) is translated to OptionalFileNotFoundError
  • a non-404 GithubException (e.g. 403) is re-raised unchanged

All existing tests still pass.

check_optional_file() only caught UnknownObjectException, but an empty
repository (one with no commits) returns a 404 that PyGithub raises as
the base GithubException ("This repository is empty."). That escaped the
handler and crashed the whole run when iterating an organization that
contains a freshly-created, never-pushed repo.

Handle a 404 GithubException the same way as a missing optional file so
the repository is skipped. Non-404 GithubExceptions are re-raised
unchanged. Adds tests for both cases.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added the fix label Jul 6, 2026
@wjglerum wjglerum marked this pull request as ready for review July 6, 2026 10:37
@jmeridth jmeridth requested a review from Copilot July 6, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR improves robustness when scanning GitHub organizations by preventing Evergreen from crashing on empty repositories (repositories with no commits) when checking for optional configuration files via PyGithub.

Changes:

  • Extend check_optional_file() to translate 404 GithubException (empty repo case) into OptionalFileNotFoundError.
  • Add unit tests covering the empty-repository 404 translation and ensuring non-404 GithubExceptions are still re-raised.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
exceptions.py Adds handling for base GithubException 404s (empty repos) to match existing optional-file behavior.
test_exceptions.py Adds test coverage for empty-repository 404 behavior and non-404 re-raise behavior.

Comment thread exceptions.py
Comment on lines +50 to +58
except GithubException as e:
# An empty repository (one with no commits) returns a 404 that PyGithub
# raises as the base GithubException ("This repository is empty.")
# rather than UnknownObjectException. Treat it the same as a missing
# optional file so the repository is skipped instead of crashing the run.
if e.status == 404:
raise OptionalFileNotFoundError(
status=e.status, data=e.data, headers=e.headers
) from e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants