{"record":{"id":"2e4c8abe34fc5c6d","repo":"kopia/kopia","slug":"invalid-ui-preferences-file","errorCode":null,"errorMessage":"invalid UI preferences file","messagePattern":"invalid UI preferences file","errorType":"http","errorClass":null,"httpStatus":500,"severity":"error","filePath":"internal/server/api_ui_pref.go","lineNumber":34,"sourceCode":"\tp := serverapi.UIPreferences{}\n\n\tif s.getOptions().UIPreferencesFile == \"\" {\n\t\treturn p, nil\n\t}\n\n\tf, err := os.Open(s.getOptions().UIPreferencesFile)\n\tif os.IsNotExist(err) {\n\t\treturn p, nil\n\t}\n\n\tif err != nil {\n\t\treturn p, errors.Wrap(err, \"unable to open UI preferences file\")\n\t}\n\n\tdefer f.Close() //nolint:errcheck\n\n\tif err := json.NewDecoder(f).Decode(&p); err != nil {\n\t\treturn p, errors.Wrap(err, \"invalid UI preferences file\")\n\t}\n\n\treturn p, nil\n}\n\nfunc handleGetUIPreferences(_ context.Context, rc requestContext) (any, *apiError) {\n\tp, err := getUIPreferencesOrEmpty(rc.srv)\n\tif err != nil {\n\t\treturn nil, internalServerError(err)\n\t}\n\n\treturn &p, nil\n}\n\nfunc handleSetUIPreferences(_ context.Context, rc requestContext) (any, *apiError) {\n\tvar p serverapi.UIPreferences\n\n\t// verify the JSON is valid by unmarshaling it","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/kopia/kopia/blob/82495e54b584c1ef6073c9e1be048f57f8aef078/internal/server/api_ui_pref.go#L16-L52","documentation":"Thrown by getUIPreferencesOrEmpty when the UI preferences file opens successfully but json.NewDecoder(f).Decode fails, meaning the file content is not valid JSON or does not decode into the expected preferences structure.","triggerScenarios":"GET UI preferences when UIPreferencesFile contains malformed JSON (truncated write, manual edit with syntax error, wrong file supplied).","commonSituations":"Hand-edited preferences file with a trailing comma or comments; file truncated by a crash or full disk; user pointed the option at a non-JSON file.","solutions":["Validate the file with a JSON linter and fix syntax errors.","Restore the file from backup or delete it (it will be recreated with empty preferences).","Check the wrapped Decode error for the exact JSON offset of the problem.","Ensure writes to the file are atomic (write temp file + rename) to avoid truncation."],"exampleFix":"// before\n{ \"theme\": \"dark\", }\n// after: valid JSON\n{ \"theme\": \"dark\" }","handlingStrategy":"fallback","validationCode":"b, err := os.ReadFile(prefsFile)\nif err == nil {\n    var p map[string]any\n    if err := json.Unmarshal(b, &p); err != nil { return fmt.Errorf(\"invalid prefs JSON: %w\", err) }\n}","typeGuard":null,"tryCatchPattern":"prefs, err := client.GetUIPreferences(ctx)\nif err != nil && strings.Contains(err.Error(), \"invalid UI preferences file\") {\n    // repair or reset the file, then retry\n    return resetPrefsFileAndRetry(ctx)\n}","preventionTips":["Validate JSON before saving preferences","Write files atomically (temp file + rename) to avoid truncation","Never hand-edit preferences without re-validating","Keep a known-good backup of the preferences file"],"tags":["kopia","json","preferences","parse"],"backgroundTag":"json-parse-error","analyzedSha":"82495e54b584c1ef6073c9e1be048f57f8aef078","analyzedAt":"2026-09-07T20:35:21.689Z","contentChangedAt":"2026-09-07T20:35:21.689Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}