DenverCoder1/github-readme-streak-stats · warning · AssertionError

204

204

Error message

No contributions found.

What it means

getContributionStats() computes daily streak statistics from a contributions map keyed by date. If the map is empty — meaning the upstream contribution lookup returned nothing — there are no stats to compute, so the library throws an AssertionError carrying HTTP-style code 204 (no content). Callers are expected to render an empty/no-data response rather than a stack trace.

Solutions

  1. Check that the username/account actually exists and has public contribution data before generating stats.
  2. Verify the upstream contribution fetch (GraphQL/API call) succeeded and inspect for rate limits or auth errors that mask as empty data.
  3. Catch the AssertionError (code 204) at the API boundary and return a 204/no-content or friendly 'no contributions' response.
  4. Widen the queried date range or exclude fewer days if aggressive filtering emptied the dataset.

Example fix

// before
$stats = getContributionStats($contributions);
// after
if (empty($contributions)) {
    http_response_code(204);
    exit;
}
$stats = getContributionStats($contributions);
Defensive patterns

Strategy: try-catch

Validate before calling

if (empty($contributions)) {
    http_response_code(204);
    return;
}

Type guard

function hasContributions(array $contributions): bool {
    return count($contributions) > 0;
}

Try / catch

try {
    $stats = getContributionStats($contributions);
} catch (AssertionError $e) {
    if ($e->getCode() === 204) {
        http_response_code(204);
        return; // render empty state
    }
    throw $e;
}

Prevention

When it happens

Trigger: Passing an empty (or falsy-after-normalization) $contributions array into getContributionStats(), typically because generateStreakStats fetched a user's GitHub contribution data and got zero entries — e.g. unknown username, private profile, blocked fetch, or a date range with no recorded activity.

Common situations: New GitHub accounts with no contributions in the requested year; misspelled or non-existent usernames; GitHub API outages or rate limiting that silently yield empty data; calling getContributionStats directly in tests or scripts with a fixture that failed to load.

Understand the failure class

Background: EmptyResultError / "no results found": when an API or scraper succeeds but returns zero rows — this error's family across 9 libraries.

Related errors


AI-assisted analysis of DenverCoder1/github-readme-streak-stats@70dd50f921 (2026-09-15). Data as JSON: /api/errors/e8720616661bd0c6. Report an issue: GitHub.

Appendix: source

Thrown at src/stats.php:348

    if (empty($excludedDays)) {
        return false;
    }
    $day = date("D", strtotime($date)); // "D" = Mon, Tue, Wed, etc.
    return in_array($day, $excludedDays);
}

/**
 * Get a stats array with the contribution count, daily streak, and dates
 *
 * @param array<string,int> $contributions Y-M-D contribution dates with contribution counts
 * @param array<string> $excludedDays List of days of the week to exclude
 * @return array<string,mixed> Streak stats
 */
function getContributionStats(array $contributions, array $excludedDays = []): array
{
    // if no contributions, display error
    if (empty($contributions)) {
        throw new AssertionError("No contributions found.", 204);
    }
    $today = array_key_last($contributions);
    $first = array_key_first($contributions);
    $stats = [
        "mode" => "daily",
        "totalContributions" => 0,
        "firstContribution" => "",
        "longestStreak" => [
            "start" => $first,
            "end" => $first,
            "length" => 0,
        ],
        "currentStreak" => [
            "start" => $first,
            "end" => $first,
            "length" => 0,
        ],
        "excludedDays" => $excludedDays,

View on GitHub (pinned to 70dd50f921)