{"record":{"id":"6eca38120daf5f40","repo":"flipped-aurora/gin-vue-admin","slug":"go-w","errorCode":null,"errorMessage":"服务器未安装 Go 工具链，无法编译: %w","messagePattern":"服务器未安装 Go 工具链，无法编译: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_cli_build.go","lineNumber":82,"sourceCode":"\tif err != nil {\n\t\treturn \"\", nil, err\n\t}\n\tmanifest, err := buildSysCliManifest(cli, bindings)\n\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}","sourceCodeStart":64,"sourceCodeEnd":100,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_cli_build.go#L64-L100","documentation":"compileCliBinary shells out to the Go toolchain to cross-compile the CLI binary. Before doing anything it runs exec.LookPath(\"go\"); when the `go` executable is not found in the server's PATH, this error is returned wrapping the underlying exec error. The service cannot build without a Go toolchain installed on the host.","triggerScenarios":"Invoking BuildCliBinary or BuildCliSkill on a server where the go binary is not installed, not in PATH for the server process user, or the service runs in a slim Docker image without the Go toolchain.","commonSituations":"Deploying in distroless/alpine runtime images that only contain the compiled binary; systemd services with a restricted PATH missing /usr/local/go/bin; container images built with multi-stage builds where Go was only in the builder stage; running under a user whose PATH differs from the shell's.","solutions":["Install the Go toolchain on the server (e.g. download from go.dev/dl and extract to /usr/local/go)","Add Go to the server process PATH, e.g. set PATH=/usr/local/go/bin:$PATH in the systemd unit or container env","If using Docker, base the runtime image on golang:<ver> or install Go in the runtime stage","Verify with `sudo -u <server-user> which go` that the exact service user can find go","Precompile binaries offline and expose a download endpoint instead of compiling at runtime"],"exampleFix":"// before (dockerfile runtime stage)\nFROM alpine:3.19\n// after\nFROM golang:1.22-alpine\n# or: RUN apk add --no-cache go && export PATH=$PATH:/usr/lib/go/bin","handlingStrategy":"validation","validationCode":"if _, err := exec.LookPath(\"go\"); err != nil {\n    return errors.New(\"Go toolchain required for CLI builds is not installed on the server\")\n}","typeGuard":null,"tryCatchPattern":"bin, content, err := svc.BuildCliBinary(cli, manifest, goos, goarch)\nif err != nil {\n    if strings.Contains(err.Error(), \"未安装 Go 工具链\") {\n        return nil, errors.New(\"server missing Go toolchain; install Go or use prebuilt binaries\")\n    }\n    return err\n}","preventionTips":["Install Go in runtime container images, or pin a golang-based image","Set PATH to include /usr/local/go/bin for the service user (check systemd unit / container env)","Add a health/startup check that runs `go version` and surfaces a clear warning","Consider precompiling offline and serving downloads instead of building at runtime"],"tags":["go","environment","toolchain","path"],"backgroundTag":"command-not-found","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}