{"record":{"id":"a92554d506558fd6","repo":"benbjohnson/litestream","slug":"failed-to-format-response-w","errorCode":null,"errorMessage":"failed to format response: %w","messagePattern":"failed to format response: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/litestream/databases.go","lineNumber":52,"sourceCode":"\t}\n\n\tdatabases := make([]DatabaseInfo, 0, len(config.DBs))\n\tfor _, dbConfig := range config.DBs {\n\t\tdb, err := NewDBFromConfig(dbConfig)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tdatabases = append(databases, DatabaseInfo{\n\t\t\tPath:    db.Path(),\n\t\t\tReplica: db.Replica.Client.Type(),\n\t\t})\n\t}\n\n\tif *jsonOutput {\n\t\toutput, err := json.MarshalIndent(databases, \"\", \"  \")\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\tw := tabwriter.NewWriter(os.Stdout, 0, 8, 2, ' ', 0)\n\tdefer w.Flush()\n\n\tfmt.Fprintln(w, \"path\\treplica\")\n\tfor _, db := range databases {\n\t\tfmt.Fprintf(w, \"%s\\t%s\\n\", db.Path, db.Replica)\n\t}\n\n\treturn nil\n}\n\ntype DatabaseInfo struct {\n\tPath    string `json:\"path\"`","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/benbjohnson/litestream/blob/4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3/cmd/litestream/databases.go#L34-L70","documentation":"Wraps a `json.MarshalIndent` failure in `litestream databases --json`. After collecting database status entries, the command tries to serialize them for output; if marshaling fails (e.g. an entry contains a value JSON cannot represent, like a NaN/Inf metric or a channel), the command returns this error instead of printing output. Rare in practice, since the data structures are plain.","triggerScenarios":"A database status field carrying a non-JSON-encodable value (unsupported type, invalid float); a bug in status collection placing unexpected data in the output struct; custom/derived builds where the databases slice holds exotic types.","commonSituations":"Running patched or forked litestream builds with extra status fields; hardware/OS quirks producing NaN timing values that json rejects.","solutions":["Report/inspect the wrapped error via `%w` to find the offending field","Run the command without `--json` to get tabular output as a workaround","Upgrade to the latest litestream version — this is likely a serialization bug","If forking, validate fields added to the status struct are JSON-encodable"],"exampleFix":"// before\noutput, err := json.MarshalIndent(databases, \"\", \"  \")\nif err != nil {\n\treturn fmt.Errorf(\"failed to format response: %w\", err)\n}\n// after\noutput, err := json.MarshalIndent(databases, \"\", \"  \")\nif err != nil {\n\tlog.Debug(\"json marshal failed; falling back to table output\", \"err\", err)\n\tprintTable(databases) // fallback path\n\treturn nil\n}","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"output, err := json.MarshalIndent(databases, \"\", \"  \")\nif err != nil {\n\t// fall back to human-readable table output\n\tprintTable(databases)\n\treturn nil\n}","preventionTips":["Prefer the default table output unless JSON is needed","Keep litestream up to date to avoid serialization bugs","When forking, ensure all status fields are JSON-encodable"],"tags":["json","serialization","cli","litestream"],"backgroundTag":"json-serialization-failed","analyzedSha":"4ed7a308f6271ebfd2b0a6e4b70b03011a37e4a3","analyzedAt":"2026-09-06T18:29:25.564Z","contentChangedAt":"2026-09-06T18:29:25.564Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}