flipped-aurora/gin-vue-admin · error

自动代码目标不是普通文件: %s

Error message

自动代码目标不是普通文件: %s

What it means

Returned when os.Stat succeeds for a target path but the existing filesystem object is not a regular file (e.g. a directory, symlink to a directory, socket, or fifo). The autocode task can only atomically replace regular files, so it refuses to proceed rather than corrupting a non-file object at the target location.

Source

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

		}
		return targets[i] < targets[j]
	})

	for index, target := range targets {
		kind, _ := layout.classify(target)
		content := normalizedFiles[target]
		file := autoCodeTaskFile{
			TargetPath: target,
			Kind:       kind,
			Mode:       0o666,
			AfterHash:  hashAutoCodeContent(content),
			StagedPath: filepath.Join(stagingDir, fmt.Sprintf("%06d", index)),
		}
		stat, statErr := os.Stat(target)
		switch {
		case statErr == nil:
			if !stat.Mode().IsRegular() {
				return nil, fmt.Errorf("自动代码目标不是普通文件: %s", target)
			}
			before, readErr := os.ReadFile(target)
			if readErr != nil {
				return nil, fmt.Errorf("读取自动代码目标 %s 失败: %w", target, readErr)
			}
			file.Existed = true
			file.Mode = stat.Mode().Perm()
			file.BeforeContent = before
			file.BeforeHash = hashAutoCodeContent(before)
		case errors.Is(statErr, fs.ErrNotExist):
		default:
			return nil, fmt.Errorf("检查自动代码目标 %s 失败: %w", target, statErr)
		}
		if writeErr := replaceAutoCodeFileAtomically(file.StagedPath, content, file.Mode); writeErr != nil {
			return nil, fmt.Errorf("写入自动代码 staging 失败: %w", writeErr)
		}
		task.files = append(task.files, file)
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Inspect the target path with ls -la or os.Stat; if it is a directory, either rename the generated file or remove/move the directory (after confirming it holds nothing needed).
  2. Fix the path in the generation request so the target points to a regular file (include the filename, not just the directory).
  3. If a symlink is the target, resolve or remove the symlink before re-running the task.
  4. Add a pre-flight check in client code: skip or reject targets where stat exists and !stat.Mode().IsRegular().

Example fix

// before: target collides with a directory
TargetPath: "server/service/user"
// after: point at the actual file inside
default:
  TargetPath: "server/service/user.go"
// or pre-check
if info, err := os.Stat(target); err == nil && !info.Mode().IsRegular() {
  return fmt.Errorf("refusing non-file target %s", target)
}
Defensive patterns

Strategy: validation

Validate before calling

func ensureRegularFile(target string) error {
  info, err := os.Stat(target)
  if err != nil {
    if errors.Is(err, fs.ErrNotExist) {
      return nil // new file, fine
    }
    return err
  }
  if !info.Mode().IsRegular() {
    return fmt.Errorf("target %s exists and is not a regular file", target)
  }
  return nil
}

Type guard

func isRegularFileInfo(info fs.FileInfo) bool {
  return info.Mode().IsRegular()
}

Try / catch

// Non-file targets abort the whole task before any publish; treat as a hard request error
if err := svc.Create(c, req); err != nil {
  if strings.Contains(err.Error(), "不是普通文件") {
    return fmt.Errorf("target path collides with a directory/non-file: %v", err)
  }
  return err
}

Prevention

When it happens

Trigger: Calling Create with a target path that already exists on disk as a directory (or other non-regular file). Common when the intended output path collides with a directory name — e.g. target 'server/service/foo' where 'foo' is a directory, or a symlink pointing at a directory.

Common situations: Developer names a generated file the same as an existing package directory; a previous bad run created a directory where a file was expected; symlinked workspace layouts (e.g. pnpm-style symlinks) make the target resolve to a directory; template misconfiguration builds a wrong path that happens to match an existing directory.

Related errors


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