kovidgoyal/kitty · error
Failed to format the response as JSON: %w
Error message
Failed to format the response as JSON: %w
What it means
After successfully reading portal settings with --json, show_settings marshals the unwrapped map with json.MarshalIndent. Failure means the settings map contains a value Go's encoding/json cannot serialize (e.g. NaN, a channel, or an unsupported Variant payload type).
Source
Thrown at kittens/desktop_ui/portal.go:293
conn, err := dbus.SessionBus()
if err != nil {
return fmt.Errorf("failed to connect to system bus with error: %w", err)
}
defer conn.Close()
var response ReadAllType
response, err = fetch_settings(conn, opts.InNamespace...)
if opts.AsJson {
unwrapped := make(map[string]map[string]any, len(response))
for ns, m := range response {
w := make(map[string]any, len(m))
for k, a := range m {
w[k] = a.Value()
}
unwrapped[ns] = w
}
j, err := json.MarshalIndent(unwrapped, "", " ")
if err != nil {
return fmt.Errorf("Failed to format the response as JSON: %w", err)
}
fmt.Println(string(j))
} else {
for ns, m := range response {
fmt.Println(ns + ":")
for key, v := range m {
fmt.Printf("\t%s: %s\n", key, v)
}
}
}
if !opts.AllowOtherBackends {
is_running_self := false
if m, found := response[SETTINGS_CANARY_NAMESPACE]; found {
_, is_running_self = m[SETTINGS_CANARY_KEY]
}
if !is_running_self {
err = fmt.Errorf("the settings did not come from the desktop-ui kitten. Some other portal backend is providing the service.")
}View on GitHub (pinned to 6d5d0c4406)
Solutions
- Run without --json to print raw values and identify the offending key
- Restrict output to specific namespaces to isolate the failing entry
- Report/fix the backend that exposes the non-serializable value
Example fix
# before kitten desktop-ui show-settings --json # after kitten desktop-ui show-settings --namespace=org.freedesktop.appearance --json
Defensive patterns
Strategy: fallback
Try / catch
if err := showSettingsJSON(resp); err != nil {
// fall back to plain-text printing
printPlain(resp)
} Prevention
- Prefer namespace-scoped queries to limit surface area
- Handle both JSON and plain output paths in callers
When it happens
Trigger: A portal namespace/key whose dbus.Variant stores a type that converts to an unmarshalable Go value (unsupported concrete types, cyclic structures).
Common situations: Non-standard portal backends exposing exotic variant types; extremely unusual settings values.
Related errors
- Could not encode message to kitty with error: %w
- failed to decode cached image metadata: %w
- must specify the new contrast value
- %s is not a valid contrast value
- must specify the key
AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27).
Data as JSON: /api/errors/aa0678b30405394f.
Report an issue: GitHub.