anuraghazra/github-readme-stats · warning · MissingParamError

Missing params "username" make sure you pass the parameters

Error message

Missing params "username" make sure you pass the parameters in URL

What it means

Thrown by fetchTopLanguages when its first positional argument, username, is falsy (undefined, null, or empty string). It is raised before any network call, so it signals a contract violation by the caller, not a GitHub API problem. The message is generated by the generic MissingParamError class (src/common/error.js:49), which formats the missedParams array into the fixed string. Because the check is `if (!username)`, even whitespace-only or the string "0" edge cases aside, any absent/blank username trips it.

Source

Thrown at src/fetchers/top-languages.js:69

 */

/**
 * Fetch top languages for a given username.
 *
 * @param {string} username GitHub username.
 * @param {string[]} exclude_repo List of repositories to exclude.
 * @param {number} size_weight Weightage to be given to size.
 * @param {number} count_weight Weightage to be given to count.
 * @returns {Promise<TopLangData>} Top languages data.
 */
const fetchTopLanguages = async (
  username,
  exclude_repo = [],
  size_weight = 1,
  count_weight = 0,
) => {
  if (!username) {
    throw new MissingParamError(["username"]);
  }

  const res = await retryer(fetcher, { login: username });

  if (res.data.errors) {
    logger.error(res.data.errors);
    if (res.data.errors[0].type === "NOT_FOUND") {
      throw new CustomError(
        res.data.errors[0].message || "Could not fetch user.",
        CustomError.USER_NOT_FOUND,
      );
    }
    if (res.data.errors[0].message) {
      throw new CustomError(
        wrapTextMultiline(res.data.errors[0].message, 90, 1)[0],
        res.statusText,
      );
    }

View on GitHub (pinned to 54a7985aee)

Solutions

  1. Ensure the request URL includes a non-empty ?username=<github-login> query parameter, e.g. /api/top-langs?username=octocat.
  2. If calling fetchTopLanguages directly, pass a validated non-empty string as the first argument before invoking it.
  3. At the caller/API layer, short-circuit with your own error response when req.query.username is missing so the user gets a clearer message than the fetcher's generic one.

Example fix

// before
const topLangs = await fetchTopLanguages(req.query.username);

// after
const username = req.query.username;
if (!username || !username.trim()) {
  return res.status(400).send("username query parameter is required");
}
const topLangs = await fetchTopLanguages(username.trim());
Defensive patterns

Strategy: validation

Validate before calling

// Run before calling fetchTopLanguages
function requireUsername(username) {
  if (typeof username !== "string" || username.trim() === "") {
    throw new Error("'username' must be a non-empty string");
  }
  return username.trim();
}

// usage
const username = requireUsername(req.query.username);
const topLangs = await fetchTopLanguages(username, excludeRepo);

Type guard

/** @param {unknown} v */
function isNonEmptyString(v) {
  return typeof v === "string" && v.trim().length > 0;
}

if (!isNonEmptyString(username)) {
  return res.status(400).send("username query parameter is required");
}

Try / catch

try {
  const topLangs = await fetchTopLanguages(username);
} catch (err) {
  if (err instanceof MissingParamError && err.missedParams.includes("username")) {
    // caller-side bad request: surface a 400, do not retry
    return res.status(400).send(err.message);
  }
  throw err;
}

Prevention

When it happens

Trigger: Calling fetchTopLanguages(undefined, ...) or fetchTopLanguages("", ...) directly. Via the HTTP API (api/top-langs.js:121), this happens on a GET /api/top-langs request whose query string omits ?username= entirely, or supplies ?username= with an empty value (req.query.username is then undefined or "").

Common situations: A README card image URL where the ?username= query parameter was forgotten or auto-stripped by a markdown renderer; programmatic callers that destructure username from a config object that does not contain the key; copy-paste of the badge URL without filling in the template placeholder.

Related errors


AI-assisted analysis of anuraghazra/github-readme-stats@54a7985aee (2026-08-12). Data as JSON: /api/errors/06a1b6ff426499d7. Report an issue: GitHub.