zed-industries/zed · error · Error
Failed to parse UNIT_DATA as JSON: ${e.message}
Error message
Failed to parse UNIT_DATA as JSON: ${e.message} What it means
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.
Source
Thrown at script/cargo-timing-info.js:41
return path.join(localAppData, "Zed");
} else {
// Fallback to XDG config dir
const xdgConfigHome = process.env.XDG_CONFIG_HOME || path.join(os.homedir(), ".config");
return path.join(xdgConfigHome, "zed");
}
}
function extractUnitData(htmlContent) {
// Find the UNIT_DATA array in the file
const unitDataMatch = htmlContent.match(/const\s+UNIT_DATA\s*=\s*(\[[\s\S]*?\]);/);
if (!unitDataMatch) {
throw new Error("Could not find UNIT_DATA in the file");
}
try {
return JSON.parse(unitDataMatch[1]);
} catch (e) {
throw new Error(`Failed to parse UNIT_DATA as JSON: ${e.message}`);
}
}
function formatTime(seconds) {
if (seconds < 60) {
return `${seconds.toFixed(2)}s`;
}
const minutes = Math.floor(seconds / 60);
const remainingSeconds = seconds % 60;
return `${minutes}m ${remainingSeconds.toFixed(2)}s`;
}
function formatUnit(unit) {
let name = `${unit.name} v${unit.version}`;
if (unit.target && unit.target.trim()) {
name += ` (${unit.target.trim()})`;
}
return name;View on GitHub (pinned to bc538def45)
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.
Example fix
// before
let task = copilot.sign_in(cx);
task.await?; // error text is an opaque Debug dump
// after: classify the retryable case
use util::ResultExt;
if let Err(err) = copilot.sign_in(cx).await {
let msg = format!("{err:#}");
if msg.contains("timed out") || msg.contains("copilot sign-in") {
// transient: status was reset to NotSignedIn, safe to re-invoke
copilot.sign_in(cx).await?;
} else {
return Err(anyhow!("copilot sign-in failed: {msg}"));
}
} Defensive patterns
Strategy: retry
Validate before calling
// Check the server is Running before starting sign-in (avoids error 362)
// and confirm the LSP request timeout is generous enough for device flow.
if !matches!(copilot.status(), Status::SignedOut { .. } | Status::Unauthorized) {
return Ok(()); // nothing to sign in to
} Type guard
fn signable(status: &Status) -> bool {
matches!(
status,
Status::SignedOut { awaiting_signing_in: false } | Status::Unauthorized
)
} Try / catch
// The status is reset to NotSignedIn on failure, so one bounded retry is safe.
let mut attempt = 0;
while let Err(err) = copilot.sign_in(cx).await {
attempt += 1;
if attempt >= 2 || !format!("{err:#}").contains("copilot sign-in") {
return Err(err.context("copilot sign-in failed twice"));
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- HTTP error! status: ${response.status}
- Could not find UNIT_DATA in the file
- GraphQL error: ${JSON.stringify(data.errors)}
- Unexpected response structure: ${JSON.stringify(data)}
- Missing env var `ZED_SERVER_URL`
AI-assisted analysis of zed-industries/zed@bc538def45 (2026-08-16).
Data as JSON: /api/errors/b3ae0acee8266c18.
Report an issue: GitHub.