{"record":{"id":"bea4dc9b21f5bedc","repo":"xai-org/grok-build","slug":"npm-view-returned-empty-version-list","errorCode":null,"errorMessage":"npm view @{} returned empty version list","messagePattern":"npm view @(.+?) returned empty version list","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-update/src/version.rs","lineNumber":203,"sourceCode":"    cmd.args(&args).stdin(std::process::Stdio::null());\n    xai_grok_tools::util::detach_command(&mut cmd);\n    cmd.envs(xai_grok_tools::util::pager_env());\n    let output = cmd.output().await?;\n\n    if !output.status.success() {\n        let stderr = String::from_utf8_lossy(&output.stderr);\n        anyhow::bail!(\"npm view @{} failed: {}\", tag, stderr.trim());\n    }\n\n    let stdout = String::from_utf8(output.stdout)?;\n    let value: Value = serde_json::from_str(stdout.trim())?;\n    match value {\n        Value::String(version) => Ok(version),\n        Value::Array(values) => values\n            .iter()\n            .rev()\n            .find_map(|entry| entry.as_str().map(|item| item.to_string()))\n            .ok_or_else(|| anyhow::anyhow!(\"npm view @{} returned empty version list\", tag)),\n        _ => anyhow::bail!(\"npm view @{} returned unexpected JSON\", tag),\n    }\n}\n\n/// Fetch the latest version from GitHub Releases using `gh release list`.\n/// For alpha channel, fetches both pre-release and stable-only, returns the\n/// semver-greater — `gh release list --limit 1` orders by publication date,\n/// not semver, so we need both to guarantee correctness.\n#[doc(hidden)]\npub async fn fetch_gh_release_version(channel: &str) -> Result<String> {\n    if channel == \"alpha\" {\n        let (with_pre, stable_only) = tokio::try_join!(\n            fetch_gh_release_latest(false),\n            fetch_gh_release_latest(true),\n        )?;\n        return semver_max(&with_pre, &stable_only);\n    }\n    fetch_gh_release_latest(true).await","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-update/src/version.rs#L185-L221","documentation":"fetch_npm_tag runs `npm view @<pkg> <tag>` and parses the JSON output; if the result is a JSON array with no string entries it throws this error, since no version could be extracted. It means npm answered, but the version list was empty — the tag/dist-tag resolved to nothing.","triggerScenarios":"Calling fetch_npm_tag (via fetch_npm_version or the test helper) when `npm view` returns an empty array (Value::Array with no string items) for the requested tag — e.g. a dist-tag pointing at no versions or an unpublished package.","commonSituations":"Querying an npm tag that doesn't exist or was removed; a freshly published package whose dist-tags haven't propagated; private/registry-scoped packages where npm returns an empty list instead of an error; misconfigured registry mirror returning empty arrays.","solutions":["Verify the package and tag exist: run `npm view @<pkg> <tag>` manually","Use a tag that resolves to published versions (e.g. \"latest\")","Check npm registry configuration (.npmrc) — point at the correct public registry","Retry after re-publishing if the package was just published"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"// pre-check that the tag resolves\nlet out = std::process::Command::new(\"npm\")\n    .args([\"view\", &format!(\"@{pkg}\"), tag, \"--json\"])\n    .output()?;\nif out.stdout.trim() == \"[]\" || out.stdout.trim().is_empty() {\n    anyhow::bail!(\"tag @{pkg} {tag} resolves to no versions\");\n}","typeGuard":null,"tryCatchPattern":"match fetch_npm_tag(pkg, tag).await {\n    Err(e) if e.to_string().contains(\"returned empty version list\") => {\n        // fall back to a known tag\n        fetch_npm_tag(pkg, \"latest\").await\n    }\n    result => result,\n}","preventionTips":["Confirm the dist-tag exists with `npm view @<pkg>` before querying","Use the standard \"latest\" tag unless a pre-release is specifically needed","Check .npmrc registry settings point at a reachable, correct registry","Retry after publication delays when packages were just published"],"tags":["npm","version","registry","network"],"backgroundTag":"empty-npm-version-list","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}