{"record":{"id":"aa0678b30405394f","repo":"kovidgoyal/kitty","slug":"failed-to-format-the-response-as-json-w","errorCode":null,"errorMessage":"Failed to format the response as JSON: %w","messagePattern":"Failed to format the response as JSON: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kittens/desktop_ui/portal.go","lineNumber":293,"sourceCode":"\tconn, err := dbus.SessionBus()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to connect to system bus with error: %w\", err)\n\t}\n\tdefer conn.Close()\n\tvar response ReadAllType\n\tresponse, err = fetch_settings(conn, opts.InNamespace...)\n\tif opts.AsJson {\n\t\tunwrapped := make(map[string]map[string]any, len(response))\n\t\tfor ns, m := range response {\n\t\t\tw := make(map[string]any, len(m))\n\t\t\tfor k, a := range m {\n\t\t\t\tw[k] = a.Value()\n\t\t\t}\n\t\t\tunwrapped[ns] = w\n\t\t}\n\t\tj, err := json.MarshalIndent(unwrapped, \"\", \"  \")\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"Failed to format the response as JSON: %w\", err)\n\t\t}\n\t\tfmt.Println(string(j))\n\t} else {\n\t\tfor ns, m := range response {\n\t\t\tfmt.Println(ns + \":\")\n\t\t\tfor key, v := range m {\n\t\t\t\tfmt.Printf(\"\\t%s: %s\\n\", key, v)\n\t\t\t}\n\t\t}\n\t}\n\tif !opts.AllowOtherBackends {\n\t\tis_running_self := false\n\t\tif m, found := response[SETTINGS_CANARY_NAMESPACE]; found {\n\t\t\t_, is_running_self = m[SETTINGS_CANARY_KEY]\n\t\t}\n\t\tif !is_running_self {\n\t\t\terr = fmt.Errorf(\"the settings did not come from the desktop-ui kitten. Some other portal backend is providing the service.\")\n\t\t}","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/kovidgoyal/kitty/blob/6d5d0c440603ad9bdf6dcd599f73f6dde21acb44/kittens/desktop_ui/portal.go#L275-L311","documentation":"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).","triggerScenarios":"A portal namespace/key whose dbus.Variant stores a type that converts to an unmarshalable Go value (unsupported concrete types, cyclic structures).","commonSituations":"Non-standard portal backends exposing exotic variant types; extremely unusual settings values.","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"],"exampleFix":"# before\nkitten desktop-ui show-settings --json\n# after\nkitten desktop-ui show-settings --namespace=org.freedesktop.appearance --json","handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := showSettingsJSON(resp); err != nil {\n    // fall back to plain-text printing\n    printPlain(resp)\n}","preventionTips":["Prefer namespace-scoped queries to limit surface area","Handle both JSON and plain output paths in callers"],"tags":["json","desktop-ui","serialization"],"backgroundTag":"json-marshal-failed","analyzedSha":"6d5d0c440603ad9bdf6dcd599f73f6dde21acb44","analyzedAt":"2026-08-27T14:20:20.142Z","schemaVersion":2},"datasetVersion":"2026-08-27T19:17:21.184Z"}