benbjohnson/litestream · warning

failed to format response: %w

Error message

failed to format response: %w

What it means

printStartStopResult failed to json.MarshalIndent the StartStopResult for -json output. In practice MarshalIndent on this all-string/uint64 struct never fails, so this is a defensive error path; it would only trigger if the struct gained an unsupported field type (e.g. a channel or func) in the future.

Source

Thrown at cmd/litestream/start.go:113

		return err
	}

	return nil
}

type StartStopResult struct {
	Status string `json:"status"`
	DBPath string `json:"db_path"`
	State  string `json:"state"`
	TXID   uint64 `json:"txid"`
	Socket string `json:"socket"`
}

func printStartStopResult(result StartStopResult, jsonOutput bool) error {
	if jsonOutput {
		output, err := json.MarshalIndent(result, "", "  ")
		if err != nil {
			return fmt.Errorf("failed to format response: %w", err)
		}
		fmt.Println(string(output))
		return nil
	}

	fmt.Printf("status: %s\n", result.Status)
	fmt.Printf("db_path: %s\n", result.DBPath)
	fmt.Printf("state: %s\n", result.State)
	fmt.Printf("txid: %d\n", result.TXID)
	fmt.Printf("socket: %s\n", result.Socket)

	return nil
}

// Usage prints the help text for the start command.
func (c *StartCommand) Usage() {
	fmt.Println(`
usage: litestream start [OPTIONS] DB_PATH

View on GitHub (pinned to 4ed7a308f6)

Solutions

  1. No user action needed; the current struct is always marshalable
  2. If you modified StartStopResult, remove or pre-convert any chan/func/custom fields to JSON-safe types
  3. Use json output normally; if you somehow see this, report it with your litestream version

Example fix

// before
type StartStopResult struct {
    Hook func() `json:"hook"` // unmarshalable
}
// after
type StartStopResult struct {
    Status string `json:"status"`
    DBPath string `json:"db_path"`
    State  string `json:"state"`
    TXID   uint64 `json:"txid"`
    Socket string `json:"socket"`
}
Defensive patterns

Strategy: validation

Prevention

When it happens

Trigger: Calling printStartStopResult(result, true) where result contains a value json cannot encode — not reachable with the current StartStopResult fields (Status, DBPath, State, TXID, Socket).

Common situations: Only arises during development if StartStopResult is extended with unmarshalable types (chan, func, cyclic pointers).

Understand the failure class

Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.

Related errors


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