{"record":{"id":"161cbfb3e5459a81","repo":"flipped-aurora/gin-vue-admin","slug":"w-161cbf","errorCode":null,"errorMessage":"解析编译目录失败: %w","messagePattern":"解析编译目录失败: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_cli_build.go","lineNumber":86,"sourceCode":"\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\tapplyCliBuildBaseURL(&manifest, req.BaseURL)\n\tmanifestBytes, err := marshalSysCliManifest(manifest)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\treturn s.compileCliBinary(cli, manifestBytes, goos, goarch)\n}\n\n// compileCliBinary 把 manifest 内嵌进 gva 源码副本并交叉编译，返回二进制文件名与内容。\nfunc (s *cliService) compileCliBinary(cli autoModel.SysCli, manifestBytes []byte, goos, goarch string) (string, []byte, error) {\n\tif _, err := exec.LookPath(\"go\"); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"服务器未安装 Go 工具链，无法编译: %w\", err)\n\t}\n\tabsBuildRoot, err := filepath.Abs(cliBuildDir)\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"解析编译目录失败: %w\", err)\n\t}\n\tif err := os.MkdirAll(absBuildRoot, 0o755); err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"创建编译根目录失败: %w\", err)\n\t}\n\n\tbuildDir, err := os.MkdirTemp(absBuildRoot, \"cli-\")\n\tif err != nil {\n\t\treturn \"\", nil, fmt.Errorf(\"创建编译目录失败: %w\", err)\n\t}\n\tdefer os.RemoveAll(buildDir)\n\n\tif err := copyCliSources(cliSourceDir, buildDir); err != nil {\n\t\treturn \"\", nil, err\n\t}\n\tif err := writeEmbeddedManifest(buildDir, manifestBytes); err != nil {\n\t\treturn \"\", nil, err\n\t}\n","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_cli_build.go#L68-L104","documentation":"compileCliBinary resolves the absolute path of cliBuildDir (the root directory used for CLI builds) via filepath.Abs. If Abs fails — which can happen when the process working directory has been removed or cannot be resolved — this wrapped error is returned and the build aborts. It is a defensive wrap around a normally-infallible call.","triggerScenarios":"The server process's current working directory was deleted while the process was running (common after container image rebuilds or tmp reaping), making filepath.Abs unable to resolve the relative cliBuildDir.","commonSituations":"Docker overlay filesystem cleanup removing the cwd; service started in a directory later deleted; working directory set to a removed tmp path in the systemd unit.","solutions":["Restart the server process so its working directory is valid again","Set the service's WorkingDirectory to a stable, always-existing path (e.g. /var/lib/gva)","Make cliBuildDir an absolute path in configuration so filepath.Abs has nothing to resolve","Ensure nothing external deletes the directory the process was started from"],"exampleFix":"# before (systemd)\n# no WorkingDirectory set\n# after\n[Service]\nWorkingDirectory=/var/lib/gva","handlingStrategy":"validation","validationCode":"if wd, err := os.Getwd(); err != nil {\n    return fmt.Errorf(\"process working directory unusable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"bin, content, err := svc.BuildCliBinary(cli, manifest, goos, goarch)\nif err != nil {\n    if strings.Contains(err.Error(), \"解析编译目录失败\") {\n        log.Println(\"build dir unresolvable; restart service or set absolute path\")\n    }\n    return err\n}","preventionTips":["Configure cliBuildDir as an absolute path","Set a stable WorkingDirectory in systemd/container configs","Avoid deleting the directory a running process was started from"],"tags":["go","filesystem","path-resolution"],"backgroundTag":"working-directory-missing","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}