{"record":{"id":"c25f534307c3d582","repo":"flipped-aurora/gin-vue-admin","slug":"s-c25f53","errorCode":null,"errorMessage":"自动代码目标不是普通文件: %s","messagePattern":"自动代码目标不是普通文件: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_task.go","lineNumber":127,"sourceCode":"\t\t}\n\t\treturn targets[i] < targets[j]\n\t})\n\n\tfor index, target := range targets {\n\t\tkind, _ := layout.classify(target)\n\t\tcontent := normalizedFiles[target]\n\t\tfile := autoCodeTaskFile{\n\t\t\tTargetPath: target,\n\t\t\tKind:       kind,\n\t\t\tMode:       0o666,\n\t\t\tAfterHash:  hashAutoCodeContent(content),\n\t\t\tStagedPath: filepath.Join(stagingDir, fmt.Sprintf(\"%06d\", index)),\n\t\t}\n\t\tstat, statErr := os.Stat(target)\n\t\tswitch {\n\t\tcase statErr == nil:\n\t\t\tif !stat.Mode().IsRegular() {\n\t\t\t\treturn nil, fmt.Errorf(\"自动代码目标不是普通文件: %s\", target)\n\t\t\t}\n\t\t\tbefore, readErr := os.ReadFile(target)\n\t\t\tif readErr != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"读取自动代码目标 %s 失败: %w\", target, readErr)\n\t\t\t}\n\t\t\tfile.Existed = true\n\t\t\tfile.Mode = stat.Mode().Perm()\n\t\t\tfile.BeforeContent = before\n\t\t\tfile.BeforeHash = hashAutoCodeContent(before)\n\t\tcase errors.Is(statErr, fs.ErrNotExist):\n\t\tdefault:\n\t\t\treturn nil, fmt.Errorf(\"检查自动代码目标 %s 失败: %w\", target, statErr)\n\t\t}\n\t\tif writeErr := replaceAutoCodeFileAtomically(file.StagedPath, content, file.Mode); writeErr != nil {\n\t\t\treturn nil, fmt.Errorf(\"写入自动代码 staging 失败: %w\", writeErr)\n\t\t}\n\t\ttask.files = append(task.files, file)\n\t}","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_task.go#L109-L145","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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).","Fix the path in the generation request so the target points to a regular file (include the filename, not just the directory).","If a symlink is the target, resolve or remove the symlink before re-running the task.","Add a pre-flight check in client code: skip or reject targets where stat exists and !stat.Mode().IsRegular()."],"exampleFix":"// before: target collides with a directory\nTargetPath: \"server/service/user\"\n// after: point at the actual file inside\ndefault:\n  TargetPath: \"server/service/user.go\"\n// or pre-check\nif info, err := os.Stat(target); err == nil && !info.Mode().IsRegular() {\n  return fmt.Errorf(\"refusing non-file target %s\", target)\n}","handlingStrategy":"validation","validationCode":"func ensureRegularFile(target string) error {\n  info, err := os.Stat(target)\n  if err != nil {\n    if errors.Is(err, fs.ErrNotExist) {\n      return nil // new file, fine\n    }\n    return err\n  }\n  if !info.Mode().IsRegular() {\n    return fmt.Errorf(\"target %s exists and is not a regular file\", target)\n  }\n  return nil\n}","typeGuard":"func isRegularFileInfo(info fs.FileInfo) bool {\n  return info.Mode().IsRegular()\n}","tryCatchPattern":"// Non-file targets abort the whole task before any publish; treat as a hard request error\nif err := svc.Create(c, req); err != nil {\n  if strings.Contains(err.Error(), \"不是普通文件\") {\n    return fmt.Errorf(\"target path collides with a directory/non-file: %v\", err)\n  }\n  return err\n}","preventionTips":["Always include the full filename (not a directory) in generation target paths.","Pre-scan requested targets with os.Stat and reject any that exist as directories or symlinks-to-non-files.","Clean up prior failed generations that may have left directories where files are expected."],"tags":["go","filesystem","not-a-regular-file","autocode"],"backgroundTag":"target-is-not-a-regular-file","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}