{"record":{"id":"3a77c12477b7be09","repo":"badges/shields","slug":"version-not-found-3a77c1","errorCode":null,"errorMessage":"version not found","messagePattern":"version not found","errorType":"exception","errorClass":"InvalidResponse","httpStatus":null,"severity":"error","filePath":"services/gem/gem-downloads.service.js","lineNumber":104,"sourceCode":"      },\n    })\n\n    let wantedVersion\n    if (version === 'stable') {\n      wantedVersion = latestVersion(\n        json\n          .filter(({ prerelease }) => !prerelease)\n          .map(({ number }) => number),\n      )\n    } else {\n      wantedVersion = version\n    }\n\n    const versionData = json.find(({ number }) => number === wantedVersion)\n    if (versionData) {\n      return versionData.downloads_count\n    } else {\n      throw new InvalidResponse({\n        prettyMessage: 'version not found',\n      })\n    }\n  }\n\n  async fetchDownloadCountForGem({ gem }) {\n    const { downloads: totalDownloads, version_downloads: versionDownloads } =\n      await this._requestJson({\n        url: `https://rubygems.org/api/v1/gems/${gem}.json`,\n        schema: gemSchema,\n        httpErrors: {\n          404: 'gem not found',\n        },\n      })\n    return { totalDownloads, versionDownloads }\n  }\n\n  async handle({ variant, gem, version }) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/badges/shields/blob/766fd8bc89a90b8534dc573ab72dec30215ab1ec/services/gem/gem-downloads.service.js#L86-L122","documentation":"Thrown in GemDownloadsService.fetchDownloadCountForVersion when the RubyGems API response for a gem contains no version entry whose number equals the requested version. The service searches the versions JSON for number === wantedVersion and raises InvalidResponse 'version not found' if no element matches.","triggerScenarios":"Requesting a downloads badge with a specific version (dv variant) that the gem has never published, e.g. /gem/dv/rails/99.9.9, or when 'stable' resolved to a version that is absent from the returned payload.","commonSituations":"Typo in the version string (missing patch segment, extra 'v' prefix like v2.3.1); querying a gem after its versions were yanked; badge cached with a pre-release that was later deleted.","solutions":["Check the exact published version with `gem list -r <gem> -a` or rubygems.org/gems/<gem>/versions","Remove the leading 'v' from the badge URL — RubyGems version numbers have no prefix","Verify the version is not yanked; use a released version","If using 'stable', confirm the gem has a stable (non-prerelease) version"],"exampleFix":"// before\n/gem/dv/mygem/v1.2.3\n// after\n/gem/dv/mygem/1.2.3","handlingStrategy":"validation","validationCode":"const versions = await fetch(`https://rubygems.org/api/v1/versions/${gem}.json`).then(r => r.json());const exists = versions.some(v => v.number === wantedVersion);if (!exists) console.warn(`${gem} has no version ${wantedVersion}`);","typeGuard":"const hasVersion = (list, v) => Array.isArray(list) && list.some(e => e?.number === v);","tryCatchPattern":"try { count = await getGemDownloads(gem, version); } catch (e) { if (String(e.message).includes('version not found')) { count = await getGemDownloads(gem, 'stable'); } else { throw e; } }","preventionTips":["Use exact RubyGems version strings without a 'v' prefix","Check rubygems.org versions page before hardcoding a version","Avoid referencing yanked or pre-release versions in badges"],"tags":["rubygems","not-found","version"],"backgroundTag":"version-not-found","analyzedSha":"766fd8bc89a90b8534dc573ab72dec30215ab1ec","analyzedAt":"2026-08-30T01:40:27.499Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}