{"record":{"id":"1d0aba2de7e551c8","repo":"plandex-ai/plandex","slug":"error-unmarshalling-apply-file-v","errorCode":null,"errorMessage":"error unmarshalling apply file: %v","messagePattern":"error unmarshalling apply file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/server/db/result_helpers.go","lineNumber":1066,"sourceCode":"\t\t\tdefer func() {\n\t\t\t\tif r := recover(); r != nil {\n\t\t\t\t\tlog.Printf(\"panic in GetPlanApplies: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\terrCh <- fmt.Errorf(\"panic in GetPlanApplies: %v\\n%s\", r, debug.Stack())\n\t\t\t\t\truntime.Goexit() // don't allow outer function to continue and double-send to channel\n\t\t\t\t}\n\t\t\t}()\n\t\t\tbytes, err := os.ReadFile(filepath.Join(appliesDir, file.Name()))\n\n\t\t\tif err != nil {\n\t\t\t\terrCh <- fmt.Errorf(\"error reading apply file: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tvar apply PlanApply\n\t\t\terr = json.Unmarshal(bytes, &apply)\n\n\t\t\tif err != nil {\n\t\t\t\terrCh <- fmt.Errorf(\"error unmarshalling apply file: %v\", err)\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tmu.Lock()\n\t\t\tplanApplies = append(planApplies, &apply)\n\t\t\tmu.Unlock()\n\n\t\t\terrCh <- nil\n\t\t}(file)\n\t}\n\n\tfor i := 0; i < len(files); i++ {\n\t\terr := <-errCh\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error getting plan applies: %v\", err)\n\t\t}\n\t}\n","sourceCodeStart":1048,"sourceCodeEnd":1084,"githubUrl":"https://github.com/plandex-ai/plandex/blob/e2d772072efadbe41d2946d97d79be55532dbab5/app/server/db/result_helpers.go#L1048-L1084","documentation":"An apply file was read successfully but json.Unmarshal into PlanApply failed. This means at least one *.json file in the applies directory is not valid PlanApply JSON — corrupt, truncated, empty, or written by an incompatible schema version.","triggerScenarios":"Calling GetPlanApplies when any file in the applies dir is corrupt: crash mid-write, manual edit, zero-byte file, or on-disk schema drift from an older Plandex version.","commonSituations":"Server crash or power loss during an apply write; data restored from a partial backup; hand-rolled scripts writing into the applies directory.","solutions":["Validate each apply file with a JSON linter; find and fix/repair the malformed one (the wrapped error names the json offset/field).","Restore the corrupt file from backup or remove it if it holds no needed data.","Check disk space and prior crash logs to explain truncation.","Upgrade the server if an old schema version wrote the file."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"files, _ := os.ReadDir(appliesDir)\nfor _, f := range files {\n    raw, err := os.ReadFile(filepath.Join(appliesDir, f.Name()))\n    if err == nil {\n        var probe map[string]any\n        if json.Unmarshal(raw, &probe) != nil {\n            return fmt.Errorf(\"apply file %s is not valid JSON\", f.Name())\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"applies, err := GetPlanApplies(orgId, planId)\nif err != nil {\n    if strings.Contains(err.Error(), \"error unmarshalling apply file\") {\n        return nil, fmt.Errorf(\"a stored apply file is corrupt; inspect the applies dir: %w\", err)\n    }\n    return nil, err\n}","preventionTips":["Write apply files atomically (temp file + rename).","Restore data from complete backups only; verify JSON before swapping in restored files.","Keep the server version consistent with the on-disk data schema."],"tags":["go","json","data-corruption"],"backgroundTag":"json-unmarshal-failed","analyzedSha":"e2d772072efadbe41d2946d97d79be55532dbab5","analyzedAt":"2026-09-05T20:56:53.631Z","contentChangedAt":"2026-09-05T20:56:53.631Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}