flipped-aurora/gin-vue-admin · error · errAutoCodeDuplicateTarget

%w: %s

Error message

%w: %s

What it means

This error is returned by prepareAutoCodeFileTask when the caller submitted two or more target file paths that resolve to the same cleaned absolute path. The duplicate-target sentinel errAutoCodeDuplicateTarget ("自动代码任务包含重复目标") is wrapped with the offending path, so callers can detect it with errors.Is. It protects the staging/commit pipeline from processing the same file twice with conflicting contents.

Source

Thrown at server/service/system/auto_code_task.go:96

		stagingDir: stagingDir,
		files:      make([]autoCodeTaskFile, 0, len(files)),
	}
	defer func() {
		if err != nil {
			task.cleanup()
		}
	}()

	targets := make([]string, 0, len(files))
	normalizedFiles := make(map[string][]byte, len(files))
	for target, content := range files {
		absoluteTarget, absoluteErr := filepath.Abs(target)
		if absoluteErr != nil {
			return nil, fmt.Errorf("解析目标路径 %q 失败: %w", target, absoluteErr)
		}
		cleanTarget := filepath.Clean(absoluteTarget)
		if _, exists := normalizedFiles[cleanTarget]; exists {
			return nil, fmt.Errorf("%w: %s", errAutoCodeDuplicateTarget, cleanTarget)
		}
		if _, classifyErr := layout.classify(cleanTarget); classifyErr != nil {
			return nil, classifyErr
		}
		normalizedFiles[cleanTarget] = content
		targets = append(targets, cleanTarget)
	}
	sort.Slice(targets, func(i, j int) bool {
		leftKind, _ := layout.classify(targets[i])
		rightKind, _ := layout.classify(targets[j])
		if leftKind != rightKind {
			return leftKind == autoCodeTaskBackend
		}
		return targets[i] < targets[j]
	})

	for index, target := range targets {
		kind, _ := layout.classify(target)

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Deduplicate the requested file paths before calling Create, keeping one entry per cleaned absolute path (e.g. via filepath.Clean/filepath.Abs on each key).
  2. Check the request payload on the frontend side for paths that differ only in normalization ('./' prefix, '..' segments, duplicate slashes) and merge them.
  3. If two different contents are genuinely intended for one path, decide on one and remove the other — the task cannot reconcile conflicting contents.
  4. In tests or tooling, verify with errors.Is(err, system errAutoCodeDuplicateTarget) to surface which path was duplicated (it is appended after the sentinel message).

Example fix

// before
files := map[string][]byte{
  "./server/service/foo.go": contentA,
  "server/service/foo.go":   contentB, // duplicate after Clean
}
// after
files := map[string][]byte{
  "server/service/foo.go": contentA, // single normalized entry
}
Defensive patterns

Strategy: validation

Validate before calling

func validateNoDuplicateTargets(paths []string) error {
  seen := make(map[string]struct{}, len(paths))
  for _, p := range paths {
    abs, err := filepath.Abs(p)
    if err != nil {
      return err
    }
    clean := filepath.Clean(abs)
    if _, dup := seen[clean]; dup {
      return fmt.Errorf("duplicate target: %s", clean)
    }
    seen[clean] = struct{}{}
  }
  return nil
}

Try / catch

// Go: detect the sentinel after a Create call
if err := svc.Create(c, req); err != nil {
  if errors.Is(err, system.ErrAutoCodeDuplicateTarget) {
    // surface the duplicated path appended in the message
    return fmt.Errorf("request contains a duplicated target: %v", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling Create (which routes to prepareRequestFileTask -> prepareAutoCodeFileTask) with a files map or request containing two entries whose paths differ textually but normalize to the same target after filepath.Abs + filepath.Clean — e.g. './server/main.go' and 'server/main.go', or paths containing redundant separators or '..' segments.

Common situations: Client-side code builds the file list by concatenating backend and frontend generation outputs where the same path can appear in both lists; templates that emit both an existing file and a generated file for the same location; manual API calls with copied paths differing only by a './' prefix or trailing separators.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/0ee706c5967d33db. Report an issue: GitHub.