{"record":{"id":"944854912f4e263c","repo":"zed-industries/zed","slug":"could-not-find-unit-data-in-the-file","errorCode":null,"errorMessage":"Could not find UNIT_DATA in the file","messagePattern":"Could not find UNIT_DATA in the file","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"script/cargo-timing-info.js","lineNumber":35,"sourceCode":"    }\n    const xdgDataHome = process.env.XDG_DATA_HOME || path.join(os.homedir(), \".local\", \"share\");\n    return path.join(xdgDataHome, \"zed\");\n  } else if (platform === \"win32\") {\n    // Windows: LocalAppData/Zed\n    const localAppData = process.env.LOCALAPPDATA || path.join(os.homedir(), \"AppData\", \"Local\");\n    return path.join(localAppData, \"Zed\");\n  } else {\n    // Fallback to XDG config dir\n    const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), \".config\");\n    return path.join(xdgConfigHome, \"zed\");\n  }\n}\n\nfunction extractUnitData(htmlContent) {\n  // Find the UNIT_DATA array in the file\n  const unitDataMatch = htmlContent.match(/const\\s+UNIT_DATA\\s*=\\s*(\\[[\\s\\S]*?\\]);/);\n  if (!unitDataMatch) {\n    throw new Error(\"Could not find UNIT_DATA in the file\");\n  }\n\n  try {\n    return JSON.parse(unitDataMatch[1]);\n  } catch (e) {\n    throw new Error(`Failed to parse UNIT_DATA as JSON: ${e.message}`);\n  }\n}\n\nfunction formatTime(seconds) {\n  if (seconds < 60) {\n    return `${seconds.toFixed(2)}s`;\n  }\n  const minutes = Math.floor(seconds / 60);\n  const remainingSeconds = seconds % 60;\n  return `${minutes}m ${remainingSeconds.toFixed(2)}s`;\n}\n","sourceCodeStart":17,"sourceCodeEnd":53,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/script/cargo-timing-info.js#L17-L53","documentation":"Thrown by CopilotServer::as_running() when the Copilot extension is in its Error state, meaning the background language-server start task already failed and the failure message was stored in CopilotServer::Error(Arc<str>). The wrapper 'copilot was not started because of an error: {error}' prepends context and embeds the original start failure (e.g. npm download failure, missing binary, spawn error). Callers hit this from as_authenticated()/as_running() at buffer registration (copilot.rs:167, 202) and completion requests (copilot.rs:1019, 1191). The state is entered at copilot.rs:724-725 when start_language_server returns Err, or forced via the ZED_FORCE_COPILOT_ERROR env var for testing.","triggerScenarios":"Calling any API that routes through as_running()/as_authenticated() — register_buffer, completion, status queries — after the server start task failed (network error while fetching @github/copilot-language-server from npm, unsupported platform/architecture bail, language server process exited during initialize). Also reproducible deterministically by setting ZED_FORCE_COPILOT_ERROR=1 before launching.","commonSituations":"Offline machine or proxy blocking registry.npmjs.org so npm_install_latest_packages fails; corrupted copilot directory under paths::copilot_dir() causing spawn failure; running an unsupported platform build (e.g. FreeBSD) so copilot_lsp_native_binary_path bails; leftover Error state after a transient network outage that was never retried because only reinstall() clears it.","solutions":["Read the embedded {error} text — it is the verbatim start failure and names the real cause (network, binary, platform).","Trigger a reinstall via the copilot: Reinstall action (reinstall() at copilot.rs:841), which clears the copilot dir and re-runs the download.","If the embedded error mentions network, fix connectivity/proxy (check HTTP_PROXY/HTTPS_PROXY) and retry the reinstall.","If the embedded error is 'unsupported Copilot language server platform/architecture', the OS/arch is not linux/macOS/windows on aarch64/x86_64 — Copilot cannot run there.","Delete paths::copilot_dir() (remove_matching clears it) to force a clean install if the directory is corrupted.","Verify ZED_FORCE_COPILOT_ERROR is not set in the environment."],"exampleFix":"// before: calling completions blindly on a possibly-failed server\nlet response = copilot.completions(&cursor_position, &buffer, cx).await?;\n\n// after: check the public status first and surface a retry path\nmatch copilot.status() {\n    Status::Error(error) => {\n        // show `error` to the user and offer the Reinstall action\n        return Err(anyhow!(\"copilot failed to start: {error}\"));\n    }\n    Status::Starting { .. } => { /* wait for the start task, then retry */ }\n    _ => { let response = copilot.completions(&cursor_position, &buffer, cx).await?; }\n}","handlingStrategy":"try-catch","validationCode":"// Rust equivalent of pre-call validation: check the public status surface\n// before invoking any completion/registration API.\nuse copilot::Status;\n\nfn copilot_ready(status: &Status) -> bool {\n    matches!(status, Status::Authorized)\n}","typeGuard":"fn usable_copilot_status(status: &Status) -> bool {\n    matches!(\n        status,\n        Status::Authorized | Status::Unauthorized | Status::SigningIn { .. } | Status::SignedOut { .. }\n    )\n}","tryCatchPattern":"// Result-based (Rust): inspect the message only to classify, never to parse\nif let Err(err) = result {\n    let msg = format!(\"{err:#}\");\n    if msg.starts_with(\"copilot was not started\") {\n        // server-state error: offer Reinstall, do not retry blindly\n    }\n}","preventionTips":["Render copilot.status() in the UI (status bar item already does this) so users see Error before invoking actions.","Route all failures through one handler that maps Status::Error(e) to a Reinstall action instead of retrying the failed call.","In tests, use the ZED_FORCE_COPILOT_ERROR env var to exercise this path deterministically.","Never call completion APIs from background tasks without first checking status() on the foreground thread."],"tags":["copilot","zed","lifecycle","language-server","startup"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}