benbjohnson/litestream · error
failed to format response: %w
Error message
failed to format response: %w
What it means
When --json output is requested, Run re-marshals the successfully parsed InfoResponse with json.MarshalIndent for pretty printing. Failing here is effectively an internal invariant violation — a struct that json.Unmarshal just produced should serialize — but the error is wrapped and returned rather than ignored.
Source
Thrown at cmd/litestream/info.go:75
}
if resp.StatusCode != http.StatusOK {
var errResp litestream.ErrorResponse
if err := json.Unmarshal(body, &errResp); err == nil && errResp.Error != "" {
return fmt.Errorf("info failed: %s", errResp.Error)
}
return fmt.Errorf("info failed: %s", string(body))
}
var result litestream.InfoResponse
if err := json.Unmarshal(body, &result); err != nil {
return fmt.Errorf("failed to parse response: %w", err)
}
if *jsonOutput {
output, err := json.MarshalIndent(result, "", " ")
if err != nil {
return fmt.Errorf("failed to format response: %w", err)
}
fmt.Println(string(output))
} else {
uptime := time.Duration(result.UptimeSeconds) * time.Second
fmt.Printf("Litestream %s\n", result.Version)
fmt.Printf(" PID: %d\n", result.PID)
fmt.Printf(" Uptime: %s\n", uptime)
fmt.Printf(" Started at: %s\n", result.StartedAt.Format(time.RFC3339))
fmt.Printf(" Databases: %d\n", result.DatabaseCount)
}
return nil
}
// Usage prints the help text for the info command.
func (c *InfoCommand) Usage() {
fmt.Println(`
usage: litestream info [OPTIONS]View on GitHub (pinned to 4ed7a308f6)
Solutions
- Retry the command; if it persists, it indicates a build defect.
- Verify you are running an official litestream release binary (rebuild from a clean checkout if custom).
- Report the issue with your version string if it reproduces on an official release.
- As a workaround use non-JSON output (omit --json) which prints via fmt.Printf and avoids the marshal path.
Example fix
// before $ litestream info --json # custom build with broken marshaler // after $ go install github.com/benbjohnson/litestream/cmd/litestream@latest $ litestream info --json
Defensive patterns
Strategy: fallback
Try / catch
if err := runInfoJSON(ctx); err != nil && strings.Contains(err.Error(), "failed to format response") {
// marshal of a freshly-decoded struct should never fail; fall back to text output
return runInfoText(ctx)
} Prevention
- Run official litestream release binaries; custom patches to InfoResponse are the usual cause.
- Use non-JSON output when you do not strictly need machine-readable output.
- Report reproducible marshal failures upstream with the version string.
When it happens
Trigger: Theoretically triggered by a field in InfoResponse that cannot be marshaled (e.g. an unsupported value injected during decode such as a channel/func via custom UnmarshalJSON, or NaN-like values in custom types).
Common situations: Practically never hit by end users; encountered only with patched/modified builds of litestream where InfoResponse gained a non-JSON-serializable field or a custom marshaler with a bug.
Understand the failure class
Background: "JSON serialization failed", "not JSON serializable", "Failed to serialize": why JSON marshaling errors happen and how to fix them — this error's family across 46 libraries.
Related errors
- failed to format response: %w
- failed to marshal request: %w
- failed to format response: %w
- failed to format response: %w
- failed to marshal request: %w
AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06).
Data as JSON: /api/errors/30d2e02e82d74405.
Report an issue: GitHub.