{"record":{"id":"2f5595e5cda6b9f1","repo":"jackwener/OpenCLI","slug":"maven-central-returned-404-for-url","errorCode":null,"errorMessage":"Maven Central returned 404 for ${url}.","messagePattern":"Maven Central returned 404 for (.+?)\\.","errorType":"http","errorClass":"EmptyResultError","httpStatus":404,"severity":"warning","filePath":"clis/maven/utils.js","lineNumber":83,"sourceCode":"    if (version != null && version.length > 200) {\n        throw new ArgumentError(`maven version \"${version}\" is too long (max 200 chars).`);\n    }\n    return { groupId, artifactId, version: version ?? null };\n}\n\nexport async function mavenFetch(url, label) {\n    let resp;\n    try {\n        resp = await fetch(url, { headers: { 'user-agent': UA, accept: 'application/json' } });\n    }\n    catch (err) {\n        throw new CommandExecutionError(\n            `${label} request failed: ${err?.message ?? err}`,\n            'Check that search.maven.org is reachable from this network.',\n        );\n    }\n    if (resp.status === 404) {\n        throw new EmptyResultError(label, `Maven Central returned 404 for ${url}.`);\n    }\n    if (resp.status === 429) {\n        throw new CommandExecutionError(\n            `${label} returned HTTP 429 (rate limited)`,\n            'Maven Central throttles bursts; wait a few seconds and retry.',\n        );\n    }\n    if (!resp.ok) {\n        throw new CommandExecutionError(`${label} returned HTTP ${resp.status}`);\n    }\n    let body;\n    try {\n        body = await resp.json();\n    }\n    catch (err) {\n        throw new CommandExecutionError(`${label} returned malformed JSON: ${err?.message ?? err}`);\n    }\n    return body;","sourceCodeStart":65,"sourceCodeEnd":101,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/maven/utils.js#L65-L101","documentation":"mavenFetch() maps an HTTP 404 from search.maven.org to an EmptyResultError, indicating the requested resource (coordinate or query) does not exist on Maven Central. The library treats 'not found' as an empty-result condition rather than a hard failure.","triggerScenarios":"Querying a nonexistent groupId:artifactId, a typo'd coordinate, a removed/unpublished artifact, or a version that was never published to Central.","commonSituations":"Typos in coordinates; looking up artifacts only on JitPack/Google Maven/Nexus but not Central; snapshots that never got released; region-restricted or renamed artifacts.","solutions":["Verify the exact groupId and artifactId on https://central.sonatype.com or search.maven.org UI.","Correct typos in the coordinate string.","If expecting a version, confirm it was actually published (check 'v' URL: repo1.maven.org/maven2/g/a/v/).","Handle EmptyResultError in your code as 'no data' instead of retrying."],"exampleFix":"// before\nconst r = await searchByCoord('com.foo:does-not-exist');\n// after\ntry {\n  const r = await searchByCoord('com.google.guava:guava');\n} catch (err) {\n  if (isNotFound(err)) return null; // treat as no result\n  throw err;\n}","handlingStrategy":"try-catch","validationCode":"null","typeGuard":"null","tryCatchPattern":"try {\n  const result = await lookup(coord);\n} catch (err) {\n  if (err instanceof EmptyResultError || /404/.test(err.message)) {\n    return null; // artifact not on Maven Central\n  }\n  throw err;\n}","preventionTips":["Verify coordinates on central.sonatype.com before querying.","Remember Central hosts only released artifacts — snapshots and JitPack-only projects will 404.","Treat EmptyResultError as 'no data', not a bug.","Confirm expected versions exist under repo1.maven.org/maven2/<g>/<a>/<v>/."],"tags":["http-404","not-found","maven","empty-result"],"backgroundTag":"http-404-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}