flipped-aurora/gin-vue-admin · error
自动代码任务包含重复目标
Error message
自动代码任务包含重复目标
What it means
errAutoCodeDuplicateTarget is returned by prepareAutoCodeFileTask when the generated task contains two entries that resolve to the same target file path (or equivalent duplicates). Committing such a task would write the same file twice with possibly different content, so preparation fails fast.
Source
Thrown at server/service/system/auto_code_task.go:23
"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 string
Existed boolView on GitHub (pinned to 3136500ef3)
Solutions
- Review the request's package/abbreviation/template settings so each generated file maps to a unique path.
- Deduplicate the target list before preparing the task.
- Fix custom templates that emit the same output path more than once.
- Split the request into separate tasks if distinct content must land in the same file.
Example fix
// before: two templates write server/api/v1/foo.go outputs: ["server/api/v1/foo.go", "server/api/v1/foo.go"] // after outputs: ["server/api/v1/foo.go"]
Defensive patterns
Strategy: validation
Validate before calling
seen := map[string]bool{}
for _, p := range targetPaths {
if seen[p] {
return fmt.Errorf("重复目标路径: %s", p)
}
seen[p] = true
}
// safe to prepare the task Try / catch
task, err := prepareAutoCodeFileTask(layout, req)
if err != nil {
if errors.Is(err, errAutoCodeDuplicateTarget) {
return fmt.Errorf("请检查模板输出/请求参数, 去除重复目标文件: %w", err)
}
return err
} Prevention
- Deduplicate template output paths before sending autocode requests.
- Ensure package/abbreviation combinations yield unique file paths.
- Audit custom templates for repeated output declarations.
- Split conflicting content into separate tasks or merge templates.
When it happens
Trigger: A create/preview request whose template outputs map onto the same destination — e.g. duplicated template entries, a package/abbreviation combination colliding paths, or a request listing the same file twice (see TestPrepareAutoCodeFileTaskRejectsEquivalentDuplicateTargets).
Common situations: Custom templates duplicating output paths; autocode payloads with overlapping struct/package settings; merged requests where frontend and backend file sets intersect.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/a19c62352f74a362.
Report an issue: GitHub.