DenverCoder1/github-readme-streak-stats · warning · InvalidArgumentException
400
400
Error message
GitHub username is required.
What it means
generateStreakStats() requires a GitHub username. After stripping all characters except alphanumerics and hyphens, an empty string means no usable username was supplied, so it throws InvalidArgumentException with code 400.
Solutions
- Pass a non-empty GitHub username as the $user argument
- Validate the username client-side before calling
- Ensure the query parameter name is correct so the value isn't empty
- Use only characters valid for GitHub usernames (letters, digits, hyphens)
Example fix
// before
generateStreakStats($_GET["user"] ?? "");
// after
$user = $_GET["user"] ?? "";
if ($user === "") { http_response_code(400); exit("user required"); }
generateStreakStats($user); Defensive patterns
Strategy: validation
Validate before calling
if (!is_string($user) || preg_match('/^[a-zA-Z0-9-]{1,39}$/', $user) !== 1) { throw new InvalidArgumentException("username required"); } Type guard
function isValidGitHubUsername($u): bool { return is_string($u) && preg_match('/^[a-zA-Z0-9-]{1,39}$/', $u) === 1; } Try / catch
try { $stats = generateStreakStats($user); } catch (InvalidArgumentException $e) { if ($e->getCode() === 400) { http_response_code(400); echo "Username is required"; } } Prevention
- Validate the user parameter at the HTTP boundary before calling library functions
- Never pass raw/unsanitized query parameters
- Check for empty strings after your own trimming/sanitization
When it happens
Trigger: Calling generateStreakStats('', ...) or passing a user value made entirely of characters that get stripped (e.g. symbols or spaces).
Common situations: Missing 'user' query parameter in an HTTP integration; a client sending whitespace-only or encoded-special-character usernames.
Understand the failure class
Background: "must not be empty", "cannot be empty" — required-field validation errors across open-source libraries — this error's family across 41 libraries.
Related errors
AI-assisted analysis of DenverCoder1/github-readme-streak-stats@70dd50f921 (2026-09-15).
Data as JSON: /api/errors/9063a6f5e2152f63.
Report an issue: GitHub.
Appendix: source
Thrown at src/generator.php:16
<?php
declare(strict_types=1);
/**
* Generate streak stats for a GitHub user from request-style parameters.
*
* @param string $user GitHub username to get stats for
* @param array<string,mixed> $params Options that affect fetching and streak calculation
* @return array<string,mixed> The calculated streak stats
*/
function generateStreakStats(string $user, array $params = []): array
{
$user = preg_replace("/[^a-zA-Z0-9\-]/", "", $user);
if ($user === "") {
throw new InvalidArgumentException("GitHub username is required.", 400);
}
$startingYear = isset($params["starting_year"]) ? intval($params["starting_year"]) : null;
$mode = isset($params["mode"]) ? strval($params["mode"]) : null;
$excludeDaysRaw = isset($params["exclude_days"]) ? strval($params["exclude_days"]) : "";
$timezone = isset($params["timezone"]) ? strval($params["timezone"]) : "";
// Build cache options based on request parameters
$cacheOptions = [
"starting_year" => $startingYear,
"mode" => $mode,
"exclude_days" => $excludeDaysRaw,
"timezone" => $timezone,
];
// Check if cache is disabled
$useCache = !isset($_SERVER["DISABLE_CACHE"]) || strtolower(strval($_SERVER["DISABLE_CACHE"])) !== "true";
View on GitHub (pinned to 70dd50f921)