{"record":{"id":"af81906f95f94605","repo":"flipped-aurora/gin-vue-admin","slug":"s-af8190","errorCode":null,"errorMessage":"自动代码目标不在服务端或前端目录内: %s","messagePattern":"自动代码目标不在服务端或前端目录内: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/service/system/auto_code_task.go","lineNumber":298,"sourceCode":"\t\treturn fmt.Errorf(\"写入临时文件失败: %w\", err)\n\t}\n\tif err = os.Chmod(tmpName, mode.Perm()); err != nil {\n\t\treturn fmt.Errorf(\"设置临时文件权限失败: %w\", err)\n\t}\n\tif err = os.Rename(tmpName, target); err != nil {\n\t\treturn fmt.Errorf(\"原子替换 %s 失败: %w\", target, err)\n\t}\n\treturn nil\n}\n\nfunc (l autoCodeTaskLayout) classify(target string) (string, error) {\n\tif isPathWithin(l.serverRoot, target) {\n\t\treturn autoCodeTaskBackend, nil\n\t}\n\tif isPathWithin(l.webRoot, target) {\n\t\treturn autoCodeTaskFrontend, nil\n\t}\n\treturn \"\", fmt.Errorf(\"自动代码目标不在服务端或前端目录内: %s\", target)\n}\n\nfunc pathWithin(root string, elems ...string) (string, error) {\n\troot, err := filepath.Abs(root)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tjoined := filepath.Join(append([]string{root}, elems...)...)\n\tjoined, err = filepath.Abs(joined)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tif !isPathWithin(root, joined) {\n\t\treturn \"\", fmt.Errorf(\"路径越过根目录: %s\", joined)\n\t}\n\treturn filepath.Clean(joined), nil\n}\n","sourceCodeStart":280,"sourceCodeEnd":316,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/auto_code_task.go#L280-L316","documentation":"The auto-code task layout classifier (classify) resolves a target file path to either the backend (serverRoot) or frontend (webRoot) root by checking path containment. If the resolved target is inside neither root, it returns this error and no publish/rollback task can be prepared. It is a safety guard so generated files are only managed within the known server/web trees.","triggerScenarios":"Calling prepareAutoCodeFileTask (or the anonymous publish/rollback wrapper) with a target path configured outside both GVA_CONFIG.AutoCode server and web roots, e.g. a misconfigured AutoCode.Root or a custom template writing to an absolute path like /tmp or another project directory.","commonSituations":"config.yaml AutoCode.Root/Server/Web values pointing to relocated directories; moving the repo after generating tasks; users setting custom output dirs in the code generator UI that escape the project; symlinked paths that resolve outside the roots after filepath.Abs.","solutions":["Check server/config.yaml autoCode section: root/server/web must point at the actual server/ and web/ directories of this project.","Verify the offending target path printed in the message and trace which template/config produced it; correct it to a path inside server/ or web/.","If symlinks are involved, ensure the real (absolute) resolved path still falls under serverRoot or webRoot.","Restart the server after config changes so the autoCodeTaskLayout is rebuilt with correct roots."],"exampleFix":"// before (config.yaml)\nautoCode:\n  root: '/opt/other-project'\n// after\nautoCode:\n  root: '/path/to/gin-vue-admin'\n  server: 'server'\n  web: 'web'","handlingStrategy":"validation","validationCode":"root, _ := filepath.Abs(\"server\")\ntarget, _ := filepath.Abs(targetPath)\nrel, err := filepath.Rel(root, target)\nif err != nil || strings.HasPrefix(rel, \"..\") {\n    return fmt.Errorf(\"target %s is outside server/\", targetPath)\n}","typeGuard":null,"tryCatchPattern":"if err := prepareAutoCodeFileTask(...); err != nil {\n    if strings.Contains(err.Error(), \"不在服务端或前端目录内\") {\n        // fix autoCode config / target path and retry\n    }\n    return err\n}","preventionTips":["Keep autoCode.root/server/web in config.yaml pointing at the real project directories","Never configure custom absolute output paths outside the repo","Avoid symlinks that resolve outside the project tree","Restart the service after changing autoCode config"],"tags":["autocode","path-validation","config"],"backgroundTag":"path-outside-allowed-root","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}