flipped-aurora/gin-vue-admin · error
自动代码目标文件已被外部修改
Error message
自动代码目标文件已被外部修改
What it means
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.
Source
Thrown at server/service/system/auto_code_task.go:22
"crypto/sha256"
"encoding/hex"
"errors"
"fmt"
"io/fs"
"os"
"path/filepath"
"sort"
"strings"
)
const (
autoCodeStagingPrefix = ".autocode-staging-"
autoCodeTaskBackend = "backend"
autoCodeTaskFrontend = "frontend"
)
var (
errAutoCodeFileConflict = errors.New("自动代码目标文件已被外部修改")
errAutoCodeDuplicateTarget = errors.New("自动代码任务包含重复目标")
)
type autoCodeTaskLayout struct {
root string
serverRoot string
webRoot string
}
type autoCodeFileTask struct {
layout autoCodeTaskLayout
stagingDir string
files []autoCodeTaskFile
}
type autoCodeTaskFile struct {
TargetPath string
Kind stringView on GitHub (pinned to 3136500ef3)
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.
Example fix
// before: file edited after task creation -> commit rejects // after: restore or accept change, then re-prepare git checkout -- server/api/v1/my_api.go // re-run create/preview so baseline hash matches, then commit
Defensive patterns
Strategy: try-catch
Validate before calling
// before commit, verify targets are unchanged (mirror of internal check)
for _, t := range task.targets {
sum, err := hashFile(t.path)
if err != nil || sum != t.baselineHash {
return fmt.Errorf("目标 %s 已被外部修改, 请先处理后再提交", t.path)
}
} Try / catch
if err := commitAutoCodeFileTask(task, publish, persist); err != nil {
if errors.Is(err, errAutoCodeFileConflict) {
// prompt user: keep external edit, restore it, or re-prepare task
return handleFileConflict(task, err)
}
return err
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/b4648d0d9e583653.
Report an issue: GitHub.