{"record":{"id":"cf38b7737facb229","repo":"golangci/golangci-lint","slug":"can-t-start-tracing-w","errorCode":null,"errorMessage":"can't start tracing: %w","messagePattern":"can't start tracing: %w","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/commands/run.go","lineNumber":287,"sourceCode":"\t\t}\n\t\tif err := pprof.StartCPUProfile(f); err != nil {\n\t\t\treturn fmt.Errorf(\"can't start CPU profiling: %w\", err)\n\t\t}\n\t}\n\n\tif c.opts.MemProfilePath != \"\" {\n\t\tif rate := os.Getenv(envMemProfileRate); rate != \"\" {\n\t\t\truntime.MemProfileRate, _ = strconv.Atoi(rate)\n\t\t}\n\t}\n\n\tif c.opts.TracePath != \"\" {\n\t\tf, err := os.Create(c.opts.TracePath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't create file %s: %w\", c.opts.TracePath, err)\n\t\t}\n\t\tif err = trace.Start(f); err != nil {\n\t\t\treturn fmt.Errorf(\"can't start tracing: %w\", err)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (c *runCommand) stopTracing() error {\n\tif c.opts.CPUProfilePath != \"\" {\n\t\tpprof.StopCPUProfile()\n\t}\n\n\tif c.opts.MemProfilePath != \"\" {\n\t\tf, err := os.Create(c.opts.MemProfilePath)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"can't create file %s: %w\", c.opts.MemProfilePath, err)\n\t\t}\n\n\t\tvar ms runtime.MemStats","sourceCodeStart":269,"sourceCodeEnd":305,"githubUrl":"https://github.com/golangci/golangci-lint/blob/ed7a235d2d771152056fdc142a9855567c5796a9/pkg/commands/run.go#L269-L305","documentation":"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.","triggerScenarios":"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).","commonSituations":"Custom tooling that enables tracing itself and then runs the golangci-lint command in-process; re-entering persistentPreRunE without a matching trace.Stop.","solutions":["Stop the existing trace with trace.Stop() before invoking golangci-lint with --trace-path.","Ensure every trace.Start has a matching trace.Stop (the CLI's persistentPostRunE does this when the run completes).","Run golangci-lint as a separate process if the host program already traces itself.","Omit --trace-path when tracing is not required."],"exampleFix":"// before\ntrace.Start(os.Stdout)\nrunErr := cmd.Execute() // tracing already active\n// after\ntrace.Stop()\nrunErr := cmd.Execute()","handlingStrategy":"try-catch","validationCode":"// ensure this process has not already enabled tracing\nif !tracingActive { // your own flag around trace.Start\n\t_ = cmd.Run()\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.Run(); err != nil && strings.Contains(err.Error(), \"can't start tracing\") {\n\ttrace.Stop() // release the active trace, then retry once\n\tif retryErr := cmd.Run(); retryErr != nil {\n\t\tlog.Fatalf(\"tracing start failed: %v\", retryErr)\n\t}\n}","preventionTips":["Never call trace.Start in the embedding process before running golangci-lint with --trace-path.","Always pair trace.Start with trace.Stop.","Keep tracing flags out of shared CI command templates unless required."],"tags":["tracing","runtime-trace","cli","golangci-lint"],"backgroundTag":"trace-already-started","analyzedSha":"ed7a235d2d771152056fdc142a9855567c5796a9","analyzedAt":"2026-09-02T18:47:33.865Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}