{"record":{"id":"b3ae0acee8266c18","repo":"zed-industries/zed","slug":"failed-to-parse-unit-data-as-json-e-message","errorCode":null,"errorMessage":"Failed to parse UNIT_DATA as JSON: ${e.message}","messagePattern":"Failed to parse UNIT_DATA as JSON: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"script/cargo-timing-info.js","lineNumber":41,"sourceCode":"    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\nfunction formatUnit(unit) {\n  let name = `${unit.name} v${unit.version}`;\n  if (unit.target && unit.target.trim()) {\n    name += ` (${unit.target.trim()})`;\n  }\n  return name;","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/zed-industries/zed/blob/bc538def4545534201bbfcac4e95ac34ea6501b6/script/cargo-timing-info.js#L23-L59","documentation":"Produced at the end of Copilot::sign_in (copilot.rs:810): the whole in-flight sign-in task is remapped with task.map_err(|err| anyhow!(\"{err:?}\")), so this error is the Debug-formatted wrapper around whatever the sign-in flow returned. The underlying task (copilot.rs:758-799) sends the request::SignIn LSP request with the timeout from global_lsp_settings.get_request_timeout(), so typical inner errors are 'copilot sign-in' request failures, timeouts, or server-shutdown errors. On failure the code also resets the sign-in status to NotSignedIn via update_sign_in_status, so the extension returns to a SignedOut state that can retry.","triggerScenarios":"Calling copilot.sign_in(cx) and awaiting the returned Task while the language server fails to answer the SignIn request: request timeout exceeded (lsp.request_timeout setting, default 120s), language server process crashed or was restarted mid-flow, or the entity was dropped so this.update(cx, ...) inside the task fails.","commonSituations":"Slow GitHub device-flow authorization exceeding the configured LSP request timeout; Copilot server process crash or OOM kill during sign-in; a very low 'lsp.request_timeout' value in settings.json; antivirus on Windows killing the freshly spawned copilot-language-server process; retrying sign_in after a previous attempt left the server half-initialized.","solutions":["Retry by calling sign_in again — the error handler already reset status to NotSignedIn, so a fresh attempt is valid.","Raise the timeout: set \"lsp\": { \"request_timeout\": 300 } in settings.json (read via ProjectSettings global_lsp_settings at copilot.rs:754-756).","Check whether the copilot-language-server process is alive (ps / Task Manager) and inspect the Zed log for server stderr/crash output.","If the server crashed repeatedly, run copilot: Reinstall to get a fresh binary and retry sign-in.","Check network reachability to github.com/GitHub Enterprise URI (copilot_settings.enterprise_uri) if using GHE."],"exampleFix":"// before\nlet task = copilot.sign_in(cx);\ntask.await?; // error text is an opaque Debug dump\n\n// after: classify the retryable case\nuse util::ResultExt;\nif let Err(err) = copilot.sign_in(cx).await {\n    let msg = format!(\"{err:#}\");\n    if msg.contains(\"timed out\") || msg.contains(\"copilot sign-in\") {\n        // transient: status was reset to NotSignedIn, safe to re-invoke\n        copilot.sign_in(cx).await?;\n    } else {\n        return Err(anyhow!(\"copilot sign-in failed: {msg}\"));\n    }\n}","handlingStrategy":"retry","validationCode":"// Check the server is Running before starting sign-in (avoids error 362)\n// and confirm the LSP request timeout is generous enough for device flow.\nif !matches!(copilot.status(), Status::SignedOut { .. } | Status::Unauthorized) {\n    return Ok(()); // nothing to sign in to\n}","typeGuard":"fn signable(status: &Status) -> bool {\n    matches!(\n        status,\n        Status::SignedOut { awaiting_signing_in: false } | Status::Unauthorized\n    )\n}","tryCatchPattern":"// The status is reset to NotSignedIn on failure, so one bounded retry is safe.\nlet mut attempt = 0;\nwhile let Err(err) = copilot.sign_in(cx).await {\n    attempt += 1;\n    if attempt >= 2 || !format!(\"{err:#}\").contains(\"copilot sign-in\") {\n        return Err(err.context(\"copilot sign-in failed twice\"));\n    }\n}","preventionTips":["Set \"lsp\": { \"request_timeout\": 300 } in settings.json when GitHub device-flow prompts may be slow.","Debounce the sign-in button so SigningIn state cannot spawn concurrent attempts.","Keep the copilot-language-server process healthy (exclude it from antivirus) to avoid mid-flow crashes.","Log the full {err:#} chain, not just the Debug wrapper, when surfacing to users."],"tags":["copilot","zed","sign-in","lsp","timeout"],"backgroundTag":null,"analyzedSha":"bc538def4545534201bbfcac4e95ac34ea6501b6","analyzedAt":"2026-08-16T07:30:46.435Z","schemaVersion":2},"datasetVersion":"2026-08-16T08:17:34.114Z"}