argoproj/argo-workflows · error

%s

Error message

%s

What it means

goFmtFile runs `go fmt <filename>` on generated telemetry Go files and returns the captured stderr as the error. The error is therefore whatever the Go toolchain printed — typically 'go: cannot find main module', 'no such file', or a syntax error in the generated file. This is a code-generation-time (build-time) failure, only seen when running the telemetry builder generator.

Source

Thrown at util/telemetry/builder/common.go:57

	err = attributeHeaderTmpl.Execute(f, map[string]string{"Banner": generatedBanner, "Filename": filepath.Base(filename)})
	if err != nil {
		return err
	}
	fmt.Fprintf(f, "const(\n")
	for _, attrib := range *attributes {
		fmt.Fprintf(f, "\tAttrib%s string = `%s`\n", attrib.Name, attrib.displayName())
	}
	fmt.Fprintf(f, ")\n")
	return nil
}

func goFmtFile(filename string) error {
	cmd := exec.Command("go", "fmt", filename)
	var stderr bytes.Buffer
	cmd.Stderr = &stderr
	_, err := cmd.Output()
	if err != nil {
		return fmt.Errorf("%s", stderr.String())
	}
	return nil
}

View on GitHub (pinned to 35bff19146)

Solutions

  1. Read the returned stderr text — it names the Go toolchain problem; fix that first.
  2. Run the builder from the repo root where go.mod exists (cd argo-workflows && go run ./util/telemetry/builder).
  3. Check the generated file named in the message for syntax errors in your generator templates.
  4. Ensure `go` (a supported version) is on PATH in your environment/CI image.

Example fix

// before (run from wrong dir)
cd util/telemetry/builder && go run .
// failed to fmt: go: cannot find main module
// after
cd /path/to/argo-workflows && go run ./util/telemetry/builder
Defensive patterns

Strategy: validation

Validate before calling

// before running the builder
if _, err := exec.LookPath("go"); err != nil { return errors.New("go not on PATH") }
if _, err := os.Stat("go.mod"); err != nil { return errors.New("run the builder from the repo root") }

Try / catch

if err := goFmtFile(filename); err != nil {
    // err text IS the go toolchain stderr; surface verbatim
    return fmt.Errorf("gofmt failed for %s: %s", filename, err)
}

Prevention

When it happens

Trigger: createAttributesGo, createMetricsHelpersGo, createMetricsListGo, or createTracingGo generate a file and goFmtFile invokes `go fmt` on it while either the generated file has invalid syntax, go is missing from PATH, or the command runs outside a Go module (no go.mod).

Common situations: Running the generator from a directory without go.mod; a broken Go installation or missing go binary in CI images; edits to generator templates that emit syntactically invalid Go; running `go run ./util/telemetry/builder` outside the repo root.

Related errors


AI-assisted analysis of argoproj/argo-workflows@35bff19146 (2026-09-03). Data as JSON: /api/errors/f1c5bd3f75e7d839. Report an issue: GitHub.