{"record":{"id":"962681eef64af9ac","repo":"benbjohnson/litestream","slug":"failed-to-parse-response-w","errorCode":null,"errorMessage":"failed to parse response: %w","messagePattern":"failed to parse response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/info.go","lineNumber":69,"sourceCode":"\t}\n\tdefer resp.Body.Close()\n\n\tbody, err := io.ReadAll(resp.Body)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read response: %w\", err)\n\t}\n\n\tif resp.StatusCode != http.StatusOK {\n\t\tvar errResp litestream.ErrorResponse\n\t\tif err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != \"\" {\n\t\t\treturn fmt.Errorf(\"info failed: %s\", errResp.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"info failed: %s\", string(body))\n\t}\n\n\tvar result litestream.InfoResponse\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse response: %w\", err)\n\t}\n\n\tif *jsonOutput {\n\t\toutput, err := json.MarshalIndent(result, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to format response: %w\", err)\n\t\t}\n\t\tfmt.Println(string(output))\n\t} else {\n\t\tuptime := time.Duration(result.UptimeSeconds) * time.Second\n\t\tfmt.Printf(\"Litestream %s\\n\", result.Version)\n\t\tfmt.Printf(\"  PID:        %d\\n\", result.PID)\n\t\tfmt.Printf(\"  Uptime:     %s\\n\", uptime)\n\t\tfmt.Printf(\"  Started at: %s\\n\", result.StartedAt.Format(time.RFC3339))\n\t\tfmt.Printf(\"  Databases:  %d\\n\", result.DatabaseCount)\n\t}\n\n\treturn nil","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/info.go#L51-L87","documentation":"On HTTP 200, Run unmarshals the body into litestream.InfoResponse. If json.Unmarshal fails, the response was not valid JSON or did not match the InfoResponse schema, and Run wraps the error with this message. It signals a client/server contract mismatch or corrupted payload.","triggerScenarios":"Daemon returns 200 with an empty or malformed body; the running daemon is an older/newer version whose /info JSON schema differs from the CLI's InfoResponse struct; a proxy mangles the body.","commonSituations":"Upgraded CLI binary while the daemon process still runs an older version; partial response truncated at a JSON boundary (rare); custom builds where the endpoint output changed.","solutions":["Restart the daemon so it matches the installed CLI version, then retry.","Check `litestream version` (daemon logs) versus your CLI version and align them.","Inspect the raw endpoint output (curl the /info endpoint) to see what is actually returned.","Remove intermediaries that could rewrite or truncate the response body."],"exampleFix":"// before\n$ litestream version  # v0.5 CLI\n$ ps  # daemon still old binary from before upgrade\n// after\n$ systemctl restart litestream  # daemon now runs new binary\n$ litestream info","handlingStrategy":"try-catch","validationCode":"// verify versions before calling\nconst { stdout } = await exec('litestream version');\nconst daemonVersion = await readDaemonVersionFromLogs();\nif (stdout.trim() !== daemonVersion.trim()) throw new Error('CLI/daemon version mismatch; restart daemon');","typeGuard":null,"tryCatchPattern":"var result litestream.InfoResponse\nif err := json.Unmarshal(body, &result); err != nil {\n    // contract mismatch or corrupt payload: dump body, restart daemon to align versions, retry\n    log.Printf(\"bad /info payload: %v; body=%q\", err, body)\n    return retryAfterDaemonRestart()\n}","preventionTips":["Restart the daemon after every litestream upgrade so CLI and daemon versions match.","Test the endpoint with curl after upgrades to confirm the JSON shape.","Avoid intermediaries that can rewrite response bodies."],"tags":["json","http","version-mismatch"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}