{"record":{"id":"2b2d4fbe7132c7c1","repo":"flipped-aurora/gin-vue-admin","slug":"s-2b2d4f","errorCode":null,"errorMessage":"不支持的目标架构: %s","messagePattern":"不支持的目标架构: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/plugin/ai/service/sys_cli_build.go","lineNumber":44,"sourceCode":"\tcliBuildGOOSAllowList   = map[string]struct{}{\"windows\": {}, \"linux\": {}, \"darwin\": {}}\n\tcliBuildGOARCHAllowList = map[string]struct{}{\"amd64\": {}, \"arm64\": {}}\n)\n\n// normalizeBuildTarget 校验并归一化目标平台。空值回退到当前运行平台。\nfunc normalizeBuildTarget(goos, goarch string) (string, string, error) {\n\tgoos = strings.ToLower(strings.TrimSpace(goos))\n\tgoarch = strings.ToLower(strings.TrimSpace(goarch))\n\tif goos == \"\" {\n\t\tgoos = runtime.GOOS\n\t}\n\tif goarch == \"\" {\n\t\tgoarch = runtime.GOARCH\n\t}\n\tif _, ok := cliBuildGOOSAllowList[goos]; !ok {\n\t\treturn \"\", \"\", fmt.Errorf(\"不支持的目标系统: %s\", goos)\n\t}\n\tif _, ok := cliBuildGOARCHAllowList[goarch]; !ok {\n\t\treturn \"\", \"\", fmt.Errorf(\"不支持的目标架构: %s\", goarch)\n\t}\n\treturn goos, goarch, nil\n}\n\n// cliBinaryExt 返回目标平台对应的二进制后缀。\nfunc cliBinaryExt(goos string) string {\n\tif goos == \"windows\" {\n\t\treturn \".exe\"\n\t}\n\treturn \"\"\n}\n\n// BuildCliBinary 把指定 CLI 的 manifest 内嵌进 gva 源码副本，交叉编译出一个开箱即用的二进制。\nfunc (s *cliService) BuildCliBinary(ctx context.Context, req autoReq.BuildSysCliBinaryRequest) (string, []byte, error) {\n\tgoos, goarch, err := normalizeBuildTarget(req.GOOS, req.GOARCH)\n\tif err != nil {\n\t\treturn \"\", nil, err\n\t}","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/plugin/ai/service/sys_cli_build.go#L26-L62","documentation":"normalizeBuildTarget validates the requested target architecture against cliBuildGOARCHAllowList. If goarch (explicit or defaulted from runtime.GOARCH) is not whitelisted, the cross-compilation is refused with this error. It complements the GOOS check and prevents `go build` from failing downstream on invalid GOARCH values.","triggerScenarios":"Calling BuildCliBinary/BuildCliSkill with goarch like \"386\", \"armv7\", \"x86_64\" (wrong name; Go uses \"amd64\"), or an empty/typoed arch string, when the value is not in cliBuildGOARCHAllowList.","commonSituations":"Using x86 naming conventions (x86_64/i386) instead of Go names (amd64/386); requesting rarely-tested archs; frontend sending arch strings not normalized to Go's GOARCH vocabulary.","solutions":["Use Go GOARCH vocabulary: amd64, arm64, etc., matching cliBuildGOARCHAllowList","Leave goarch empty to default to the server's runtime.GOARCH if that is acceptable","If a new arch is genuinely needed, add it to cliBuildGOARCHAllowList and test the CGO_ENABLED=0 cross build","Normalize/validate arch input in the API layer before calling the build service"],"exampleFix":"// before\nsvc.BuildCliBinary(cli, manifest, \"linux\", \"x86_64\")\n// after\nsvc.BuildCliBinary(cli, manifest, \"linux\", \"amd64\")","handlingStrategy":"validation","validationCode":"var cliBuildGOARCHAllowList = map[string]bool{\"amd64\": true, \"arm64\": true}\nif !cliBuildGOARCHAllowList[goarch] {\n    return fmt.Errorf(\"unsupported GOARCH %q; allowed: amd64, arm64\", goarch)\n}","typeGuard":"func isSupportedGOARCH(goarch string) bool {\n    return map[string]bool{\"amd64\": true, \"arm64\": true}[goarch]\n}","tryCatchPattern":"goos, goarch, err := normalizeBuildTarget(inGoos, inGoarch)\nif err != nil {\n    return nil, fmt.Errorf(\"invalid build target: %w\", err)\n}","preventionTips":["Use Go GOARCH vocabulary (amd64, arm64, 386) — never x86_64/i386","Normalize arch aliases at the API boundary before calling the service","Leave goarch empty to inherit runtime.GOARCH when no cross-compile is needed"],"tags":["go","cross-compile","validation","whitelist"],"backgroundTag":"unsupported-build-target","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T22:30:34.772Z"}