{"record":{"id":"b4648d0d9e583653","repo":"flipped-aurora/gin-vue-admin","slug":"error-b4648d","errorCode":null,"errorMessage":"自动代码目标文件已被外部修改","messagePattern":"自动代码目标文件已被外部修改","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_task.go","lineNumber":22,"sourceCode":"\t\"crypto/sha256\"\n\t\"encoding/hex\"\n\t\"errors\"\n\t\"fmt\"\n\t\"io/fs\"\n\t\"os\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strings\"\n)\n\nconst (\n\tautoCodeStagingPrefix = \".autocode-staging-\"\n\tautoCodeTaskBackend   = \"backend\"\n\tautoCodeTaskFrontend  = \"frontend\"\n)\n\nvar (\n\terrAutoCodeFileConflict    = errors.New(\"自动代码目标文件已被外部修改\")\n\terrAutoCodeDuplicateTarget = errors.New(\"自动代码任务包含重复目标\")\n)\n\ntype autoCodeTaskLayout struct {\n\troot       string\n\tserverRoot string\n\twebRoot    string\n}\n\ntype autoCodeFileTask struct {\n\tlayout     autoCodeTaskLayout\n\tstagingDir string\n\tfiles      []autoCodeTaskFile\n}\n\ntype autoCodeTaskFile struct {\n\tTargetPath    string\n\tKind          string","sourceCodeStart":4,"sourceCodeEnd":40,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_task.go#L4-L40","documentation":"errAutoCodeFileConflict signals that an autocode task's target file changed on disk between task preparation and commit (mismatch of the recorded baseline hash/content). The publish step refuses to overwrite externally modified files, protecting hand-edits from being clobbered by generated code. Returned by publishPreparedAutoCodeFile and rollback, and asserted in the external-modification test.","triggerScenarios":"prepareAutoCodeFileTask records target state; before commitAutoCodeFileTask publishes, a file at one of the target paths is edited, regenerated, or touched by git operations/another process, so the pre-write check detects a hash mismatch.","commonSituations":"Developer edits a generated file while an autocode preview/commit is pending; a git pull or formatter rewrites files between create and commit; two autocode tasks targeting the same file overlap.","solutions":["Inspect the conflicting target file; if the external change is intentional, keep it and regenerate/adjust the task, or discard it consciously.","If the external change is unwanted, restore the file to its previous state and re-commit the task.","Re-create the autocode task (fresh prepare) so the baseline matches current disk state, then commit immediately.","Avoid editing target files between preview/create and commit; commit promptly."],"exampleFix":"// before: file edited after task creation -> commit rejects\n// after: restore or accept change, then re-prepare\ngit checkout -- server/api/v1/my_api.go\n// re-run create/preview so baseline hash matches, then commit","handlingStrategy":"try-catch","validationCode":"// before commit, verify targets are unchanged (mirror of internal check)\nfor _, t := range task.targets {\n    sum, err := hashFile(t.path)\n    if err != nil || sum != t.baselineHash {\n        return fmt.Errorf(\"目标 %s 已被外部修改, 请先处理后再提交\", t.path)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := commitAutoCodeFileTask(task, publish, persist); err != nil {\n    if errors.Is(err, errAutoCodeFileConflict) {\n        // prompt user: keep external edit, restore it, or re-prepare task\n        return handleFileConflict(task, err)\n    }\n    return err\n}","preventionTips":["Do not edit generated target files between create/preview and commit.","Commit autocode tasks promptly; avoid long-lived pending tasks across git operations.","Pause formatters/linters/watchers that rewrite files during autocode runs.","On conflict, re-prepare a fresh task so the baseline matches disk."],"tags":["autocode","conflict","concurrency","filesystem"],"backgroundTag":"file-conflict-external-modification","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}