badges/shields · error · InvalidParameter

invalid community

Error message

invalid community

What it means

The Lemmy service throws InvalidParameter when the community string does not contain exactly one '@' after splitting, i.e. it is not in the required `community@server` format. This is a client-side input validation error thrown before any network request is made, so the badge URL itself is malformed.

Source

Thrown at services/lemmy/lemmy.service.js:48

    },
  }

  static defaultBadgeData = { label: 'community', namedLogo: 'lemmy' }

  static render({ community, members }) {
    return {
      label: `subscribe to ${community}`,
      message: metric(members),
      style: 'social',
      color: 'brightgreen',
    }
  }

  async fetch({ community }) {
    const splitAlias = community.split('@')
    // The community will be in the format of `community@server`
    if (splitAlias.length !== 2) {
      throw new InvalidParameter({
        prettyMessage: 'invalid community',
      })
    }

    const host = splitAlias[1]

    const data = await this._requestJson({
      url: `https://${host}/api/v3/community`,
      schema: lemmyCommunitySchema,
      options: {
        searchParams: {
          name: community,
        },
      },
      httpErrors: {
        404: 'community not found',
      },
    })

View on GitHub (pinned to 766fd8bc89)

Solutions

  1. Format the badge URL as /lemmy/<community>@<instance>, e.g. /lemmy/lemmy@lemmy.ml.
  2. Remove any protocol prefix or trailing path from the community value.
  3. URL-encode the community name if it contains characters outside [a-zA-Z0-9_.@-].

Example fix

// before
/lemmy/lemmy
// after
/lemmy/lemmy@lemmy.ml
Defensive patterns

Strategy: validation

Validate before calling

function validateLemmyCommunity(community) {
  const parts = community.split('@');
  if (parts.length !== 2 || !parts[0] || !parts[1]) {
    throw new Error(`community must be in 'community@server' format, got: ${community}`);
  }
}

Type guard

function isCommunityAlias(value) {
  return typeof value === 'string' && value.split('@').length === 2 && value.split('@').every(Boolean);
}

Try / catch

try {
  members = await getLemmyCommunityBadge(community);
} catch (e) {
  if (e.name === 'InvalidParameter') {
    renderFallback(`'${community}' is not community@server format`);
  } else throw e;
}

Prevention

When it happens

Trigger: Calling /lemmy/<community> where community.split('@').length !== 2 — e.g. just 'lemmy' (no server), 'a@b@c' (multiple @), or an empty community segment.

Common situations: Forgetting the @server suffix in the badge URL; including 'https://' or a full URL; communities with special characters in their local name; using a URL-encoded slash that introduces extra '@' parts.

Related errors


AI-assisted analysis of badges/shields@766fd8bc89 (2026-08-30). Data as JSON: /api/errors/ffc8c39eccf6f13d. Report an issue: GitHub.