golangci/golangci-lint · error

can't start tracing: %w

Error message

can't start tracing: %w

What it means

Error in runCommand.startTracing (persistentPreRunE): when a trace file path is configured (--trace or equivalent), os.Create succeeded but trace.Start(f) failed, e.g. because execution tracing is already active in this process. The run aborts before linting begins.

Source

Thrown at pkg/commands/run.go:287

		}
		if err := pprof.StartCPUProfile(f); err != nil {
			return fmt.Errorf("can't start CPU profiling: %w", err)
		}
	}

	if c.opts.MemProfilePath != "" {
		if rate := os.Getenv(envMemProfileRate); rate != "" {
			runtime.MemProfileRate, _ = strconv.Atoi(rate)
		}
	}

	if c.opts.TracePath != "" {
		f, err := os.Create(c.opts.TracePath)
		if err != nil {
			return fmt.Errorf("can't create file %s: %w", c.opts.TracePath, err)
		}
		if err = trace.Start(f); err != nil {
			return fmt.Errorf("can't start tracing: %w", err)
		}
	}

	return nil
}

func (c *runCommand) stopTracing() error {
	if c.opts.CPUProfilePath != "" {
		pprof.StopCPUProfile()
	}

	if c.opts.MemProfilePath != "" {
		f, err := os.Create(c.opts.MemProfilePath)
		if err != nil {
			return fmt.Errorf("can't create file %s: %w", c.opts.MemProfilePath, err)
		}

		var ms runtime.MemStats

View on GitHub (pinned to ed7a235d2d)

Solutions

  1. Stop the existing trace with trace.Stop() before invoking golangci-lint with --trace-path.
  2. Ensure every trace.Start has a matching trace.Stop (the CLI's persistentPostRunE does this when the run completes).
  3. Run golangci-lint as a separate process if the host program already traces itself.
  4. Omit --trace-path when tracing is not required.

Example fix

// before
trace.Start(os.Stdout)
runErr := cmd.Execute() // tracing already active
// after
trace.Stop()
runErr := cmd.Execute()
Defensive patterns

Strategy: try-catch

Validate before calling

// ensure this process has not already enabled tracing
if !tracingActive { // your own flag around trace.Start
	_ = cmd.Run()
}

Try / catch

if err := cmd.Run(); err != nil && strings.Contains(err.Error(), "can't start tracing") {
	trace.Stop() // release the active trace, then retry once
	if retryErr := cmd.Run(); retryErr != nil {
		log.Fatalf("tracing start failed: %v", retryErr)
	}
}

Prevention

When it happens

Trigger: Running with --trace-path while another runtime/trace.Start is already active in the same process (e.g. the embedding program or a prior un-stopped run started tracing).

Common situations: Custom tooling that enables tracing itself and then runs the golangci-lint command in-process; re-entering persistentPreRunE without a matching trace.Stop.

Related errors


AI-assisted analysis of golangci/golangci-lint@ed7a235d2d (2026-09-02). Data as JSON: /api/errors/cf38b7737facb229. Report an issue: GitHub.