flipped-aurora/gin-vue-admin · error

go build 失败: %w %s

Error message

go build 失败: %w
%s

What it means

runGoBuild executes `go build` with GOOS/GOARCH/CGO_ENABLED=0 to compile the CLI binary. If the command exits non-zero, this error wraps the exec error plus the combined stdout/stderr output from the compiler, giving the developer the actual Go compile diagnostics. This is the raw compilation-failure surface of the CLI build feature.

Source

Thrown at server/plugin/ai/service/sys_cli_build.go:172

	}
	embedded := "package main\n\nimport _ \"embed\"\n\n//go:embed " + cliEmbeddedManifestName + "\nvar embeddedManifest []byte\n"
	return os.WriteFile(filepath.Join(destDir, cliEmbeddedGoName), []byte(embedded), 0o644)
}

// runGoBuild 在编译目录里交叉编译 gva。
func runGoBuild(buildDir, binaryPath, goos, goarch string) error {
	ctx, cancel := context.WithTimeout(context.Background(), cliBuildTimeout)
	defer cancel()
	cmd := exec.CommandContext(ctx, "go", "build", "-o", binaryPath, ".")
	cmd.Dir = buildDir
	cmd.Env = append(os.Environ(),
		"GOOS="+goos,
		"GOARCH="+goarch,
		"CGO_ENABLED=0",
	)
	output, err := cmd.CombinedOutput()
	if err != nil {
		return fmt.Errorf("go build 失败: %w\n%s", err, strings.TrimSpace(string(output)))
	}
	return nil
}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Read the go build output appended to this error — it names the exact file:line of the compile error
  2. Check the generated manifest embedding for unescaped characters (quotes, backticks, newlines) breaking Go syntax
  3. Verify the CLI source tree in cliSourceDir matches the current template/API the manifest expects
  4. Ensure module dependencies are available (GOFLAGS=-mod=mod, vendored deps, or network/GOPROXY access)
  5. Reproduce the build manually in a temp copy of the source dir with the same GOOS/GOARCH to iterate on fixes

Example fix

// before: raw manifest injected
content = strings.Replace(tpl, "__MANIFEST__", string(manifestBytes), 1)
// after: safely encode as string literal
lit := strconv.Quote(string(manifestBytes))
content = strings.Replace(tpl, "__MANIFEST__", lit, 1)
Defensive patterns

Strategy: try-catch

Validate before calling

if _, err := exec.LookPath("go"); err != nil {
    return errors.New("go toolchain missing")
}
json.Valid(manifestBytes) // ensure manifest is valid before embedding

Try / catch

bin, content, err := svc.BuildCliBinary(cli, manifest, goos, goarch)
if err != nil {
    var buildErr interface{ Error() string }
    if errors.As(err, &buildErr) && strings.Contains(err.Error(), "go build 失败") {
        log.Printf("compile failed with diagnostics:\n%s", err)
        return nil, fmt.Errorf("CLI compile failed; see server log for go build output")
    }
    return err
}

Prevention

When it happens

Trigger: Any Go compile error in the generated/embedded manifest code, syntax errors in the inlined manifest, undefined symbols after copying sources, or a go.mod/module path mismatch in the copied source tree. Triggered from BuildCliBinary/BuildCliSkill via compileCliBinary.

Common situations: Manifest content injected into a template producing invalid Go literals (unescaped quotes/backticks); CLI source dir out of sync with expected interfaces after a version upgrade; vendoring/module cache unavailable offline (missing deps) in sandboxed servers.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/09c7fbb536c1441b. Report an issue: GitHub.