{"record":{"id":"287091b50a36dc50","repo":"benbjohnson/litestream","slug":"failed-to-parse-response-w-287091","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/register.go","lineNumber":93,"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(\"register failed: %s\", errResp.Error)\n\t\t}\n\t\treturn fmt.Errorf(\"register failed: %s\", string(body))\n\t}\n\n\tvar result litestream.RegisterDatabaseResponse\n\tif err := json.Unmarshal(body, &result); err != nil {\n\t\treturn fmt.Errorf(\"failed to parse response: %w\", err)\n\t}\n\n\tconfirmation := RegisterResult{\n\t\tStatus:  result.Status,\n\t\tDBPath:  result.Path,\n\t\tReplica: replicaURL,\n\t\tSocket:  *socketPath,\n\t}\n\tif *jsonOutput {\n\t\toutput, err := json.MarshalIndent(confirmation, \"\", \"  \")\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\treturn nil\n\t}\n\n\tfmt.Printf(\"status: %s\\n\", registerDisplayStatus(confirmation.Status))","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/register.go#L75-L111","documentation":"On a 200 response, the command decodes the body into litestream.RegisterDatabaseResponse with json.Unmarshal. A decode failure means the daemon answered 200 but the body isn't the expected JSON schema; the error is wrapped as 'failed to parse response'.","triggerScenarios":"Daemon returns 200 with empty body, truncated JSON, or fields of unexpected types (e.g. status as a number); version mismatch between CLI and daemon changing the response schema; something other than the litestream daemon listening on the socket.","commonSituations":"Mixed litestream versions after an upgrade (old daemon, new CLI); custom reverse proxies or socket shims; daemon handler bug producing malformed JSON with a 200 status.","solutions":["Ensure CLI and daemon are the same litestream version (reinstall/restart both)","Inspect the %w-wrapped cause to see the exact unmarshal error (field/type mismatch)","Capture the raw body (e.g. with -json on an older CLI or by testing the socket with curl --unix-socket) to see what was actually returned","Confirm the process listening on the socket is the litestream daemon"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"litestream version  # verify CLI/daemon version match","typeGuard":null,"tryCatchPattern":"if err := registerCmd.Run(ctx, args); err != nil {\n    if strings.Contains(err.Error(), \"failed to parse response\") {\n        // 200 but malformed JSON: capture cause, compare versions\n        log.Printf(\"bad response from daemon: %v\", errors.Unwrap(err))\n    }\n}","preventionTips":["Upgrade/restart CLI and daemon together","Verify the socket peer is the litestream daemon","Test the socket directly (curl --unix-socket) to inspect raw JSON"],"tags":["json","ipc","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"}