benbjohnson/litestream · error

failed to format response: %w

Error message

failed to format response: %w

What it means

With -json, the command re-serializes the local RegisterResult confirmation struct with json.MarshalIndent for pretty output. If that marshal fails, it returns 'failed to format response'. Like error 151, this is effectively unreachable with the current all-string fields and signals an internal problem rather than user error.

Source

Thrown at cmd/litestream/register.go:105

		}
		return fmt.Errorf("register failed: %s", string(body))
	}

	var result litestream.RegisterDatabaseResponse
	if err := json.Unmarshal(body, &result); err != nil {
		return fmt.Errorf("failed to parse response: %w", err)
	}

	confirmation := RegisterResult{
		Status:  result.Status,
		DBPath:  result.Path,
		Replica: replicaURL,
		Socket:  *socketPath,
	}
	if *jsonOutput {
		output, err := json.MarshalIndent(confirmation, "", "  ")
		if err != nil {
			return fmt.Errorf("failed to format response: %w", err)
		}
		fmt.Println(string(output))
		return nil
	}

	fmt.Printf("status: %s\n", registerDisplayStatus(confirmation.Status))
	fmt.Printf("db_path: %s\n", confirmation.DBPath)
	fmt.Printf("replica: %s\n", confirmation.Replica)
	fmt.Printf("socket: %s\n", confirmation.Socket)

	return nil
}

type RegisterResult struct {
	Status  string `json:"status"`
	DBPath  string `json:"db_path"`
	Replica string `json:"replica"`
	Socket  string `json:"socket"`

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. Run a stock litestream build to rule out local modifications
  2. Check the wrapped %w cause and any custom MarshalJSON on RegisterResult
  3. Use non-JSON output (drop -json) as a temporary workaround
Defensive patterns

Strategy: try-catch

Try / catch

if err := registerCmd.Run(ctx, args); err != nil {
    if strings.Contains(err.Error(), "failed to format response") {
        // non-marshalable RegisterResult field — internal bug; fall back to text output
        runWithoutJSONFlag(args)
    }
}

Prevention

When it happens

Trigger: json.MarshalIndent failing on RegisterResult — only possible if fields become non-marshalable types (custom build/fork) or a custom MarshalJSON returns an error.

Common situations: Forks or patches adding complex fields to RegisterResult; custom JSON marshalers erroring; essentially never seen in stock litestream.

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


AI-assisted analysis of benbjohnson/litestream@4ed7a308f6 (2026-09-06). Data as JSON: /api/errors/7da31b4bc3536f71. Report an issue: GitHub.