{"record":{"id":"e8720616661bd0c6","repo":"DenverCoder1/github-readme-streak-stats","slug":"204-no-contributions-found","errorCode":"204","errorMessage":"No contributions found.","messagePattern":"No contributions found\\.","errorType":"exception","errorClass":"AssertionError","httpStatus":204,"severity":"warning","filePath":"src/stats.php","lineNumber":348,"sourceCode":"    if (empty($excludedDays)) {\n        return false;\n    }\n    $day = date(\"D\", strtotime($date)); // \"D\" = Mon, Tue, Wed, etc.\n    return in_array($day, $excludedDays);\n}\n\n/**\n * Get a stats array with the contribution count, daily streak, and dates\n *\n * @param array<string,int> $contributions Y-M-D contribution dates with contribution counts\n * @param array<string> $excludedDays List of days of the week to exclude\n * @return array<string,mixed> Streak stats\n */\nfunction getContributionStats(array $contributions, array $excludedDays = []): array\n{\n    // if no contributions, display error\n    if (empty($contributions)) {\n        throw new AssertionError(\"No contributions found.\", 204);\n    }\n    $today = array_key_last($contributions);\n    $first = array_key_first($contributions);\n    $stats = [\n        \"mode\" => \"daily\",\n        \"totalContributions\" => 0,\n        \"firstContribution\" => \"\",\n        \"longestStreak\" => [\n            \"start\" => $first,\n            \"end\" => $first,\n            \"length\" => 0,\n        ],\n        \"currentStreak\" => [\n            \"start\" => $first,\n            \"end\" => $first,\n            \"length\" => 0,\n        ],\n        \"excludedDays\" => $excludedDays,","sourceCodeStart":330,"sourceCodeEnd":366,"githubUrl":"https://github.com/DenverCoder1/github-readme-streak-stats/blob/70dd50f921097927dc8314ac33a04b010a09924d/src/stats.php#L330-L366","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Check that the username/account actually exists and has public contribution data before generating stats.","Verify the upstream contribution fetch (GraphQL/API call) succeeded and inspect for rate limits or auth errors that mask as empty data.","Catch the AssertionError (code 204) at the API boundary and return a 204/no-content or friendly 'no contributions' response.","Widen the queried date range or exclude fewer days if aggressive filtering emptied the dataset."],"exampleFix":"// before\n$stats = getContributionStats($contributions);\n// after\nif (empty($contributions)) {\n    http_response_code(204);\n    exit;\n}\n$stats = getContributionStats($contributions);","handlingStrategy":"try-catch","validationCode":"if (empty($contributions)) {\n    http_response_code(204);\n    return;\n}","typeGuard":"function hasContributions(array $contributions): bool {\n    return count($contributions) > 0;\n}","tryCatchPattern":"try {\n    $stats = getContributionStats($contributions);\n} catch (AssertionError $e) {\n    if ($e->getCode() === 204) {\n        http_response_code(204);\n        return; // render empty state\n    }\n    throw $e;\n}","preventionTips":["Check the contribution array for emptiness before computing stats.","Handle upstream fetch failures (rate limits, auth, network) explicitly so they don't degrade to empty data.","Validate the username exists before querying contributions.","Return a friendly empty state in the UI for accounts with no activity."],"tags":["php","empty-data","no-contributions"],"backgroundTag":"empty-result-set","analyzedSha":"70dd50f921097927dc8314ac33a04b010a09924d","analyzedAt":"2026-09-15T02:40:51.909Z","contentChangedAt":"2026-09-15T02:40:51.909Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}