{"record":{"id":"3b27b4f0c8e0dd1d","repo":"plandex-ai/plandex","slug":"error-unmarshalling-json-file-v-3b27b4","errorCode":null,"errorMessage":"error unmarshalling JSON file: %v","messagePattern":"error unmarshalling JSON file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/cli/lib/model_settings.go","lineNumber":57,"sourceCode":"\n\tif !exists {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, nil\n\t}\n\n\tlastSavedHash, err := os.ReadFile(hashPath)\n\tif err != nil && !os.IsNotExist(err) {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, fmt.Errorf(\"error reading hash file: %v\", err)\n\t}\n\n\tlocalJsonData, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, fmt.Errorf(\"error reading JSON file: %v\", err)\n\t}\n\n\tvar clientModelPackSchemaRoles *shared.ClientModelPackSchemaRoles\n\terr = json.Unmarshal(localJsonData, &clientModelPackSchemaRoles)\n\tif err != nil {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, fmt.Errorf(\"error unmarshalling JSON file: %v\", err)\n\t}\n\n\tcurrentHash, err := clientModelPackSchemaRoles.ToModelPackSchemaRoles().Hash()\n\tif err != nil {\n\t\treturn ModelSettingsCheckLocalChangesResult{}, fmt.Errorf(\"error hashing model pack: %v\", err)\n\t}\n\n\tmodelPackSchemaRoles := clientModelPackSchemaRoles.ToModelPackSchemaRoles()\n\n\treturn ModelSettingsCheckLocalChangesResult{\n\t\tHasLocalChanges:           currentHash != string(lastSavedHash),\n\t\tLocalModelPackSchemaRoles: &modelPackSchemaRoles,\n\t}, nil\n}\n\nfunc WriteModelSettingsFile(path string, originalSettings *shared.PlanSettings) error {\n\terr := os.MkdirAll(filepath.Dir(path), 0755)\n\tif err != nil {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/cli/lib/model_settings.go#L39-L75","documentation":"ModelSettingsCheckLocalChanges unmarshals the settings file contents into *shared.ClientModelPackSchemaRoles. This error wraps json.Unmarshal failure: the file exists and is readable but is not valid JSON for the expected schema, so local changes cannot be hashed or compared.","triggerScenarios":"json.Unmarshal on the settings file fails: malformed JSON, wrong schema (not a ClientModelPackSchemaRoles), truncated file from a partial write, or type mismatches (string where object expected).","commonSituations":"User hand-edited the model settings file and introduced a syntax error; an old CLI version wrote a schema the new version can't parse; the file was truncated by a crash or full disk mid-write.","solutions":["Validate the file with `jq . <settingsPath>` or a JSON linter and fix the syntax error reported by the wrapped message.","Compare against the schema expected by shared.ClientModelPackSchemaRoles and correct field names/types.","Restore the file from git or back it up and let the CLI regenerate defaults.","If upgrading from an older CLI version, migrate or delete the old-format settings file."],"exampleFix":"// before: settings.json\n{ \"roles\": { \"planner\": \"gpt-4o\", } }\n// after: remove trailing comma\n{ \"roles\": { \"planner\": \"gpt-4o\" } }","handlingStrategy":"validation","validationCode":"data, err := os.ReadFile(settingsPath)\nif err == nil {\n    var v any\n    if err := json.Unmarshal(data, &v); err != nil {\n        return fmt.Errorf(\"settings file has invalid JSON: %w\", err)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if strings.Contains(err.Error(), \"unmarshalling JSON file\") {\n        return fmt.Errorf(\"model settings file is malformed — validate with `jq . %s` or restore from git: %w\", settingsPath, err)\n    }\n    return err\n}","preventionTips":["Validate the settings file with a JSON linter after every manual edit.","Back up or commit the file so it can be restored from git.","Don't edit while a write is in progress — check for truncation after crashes.","When upgrading CLI versions, confirm the settings schema matches ClientModelPackSchemaRoles."],"tags":["json","validation","settings","schema"],"backgroundTag":"json-parse-error","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}