{"record":{"id":"13d84285d9d7b975","repo":"gohugoio/hugo","slug":"failed-to-start-trace-w","errorCode":null,"errorMessage":"failed to start trace: %w","messagePattern":"failed to start trace: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/hugobuilder.go","lineNumber":304,"sourceCode":"\n\t\tif stopMemTicker != nil {\n\t\t\tstopMemTicker()\n\t\t}\n\t}, nil\n}\n\nfunc (c *hugoBuilder) initTraceProfile() (func(), error) {\n\tif c.r.traceprofile == \"\" {\n\t\treturn nil, nil\n\t}\n\n\tf, err := os.Create(c.r.traceprofile)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to create trace file: %w\", err)\n\t}\n\n\tif err := trace.Start(f); err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to start trace: %w\", err)\n\t}\n\n\treturn func() {\n\t\ttrace.Stop()\n\t\tf.Close()\n\t}, nil\n}\n\n// newWatcher creates a new watcher to watch filesystem events.\nfunc (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*watcher.Batcher, error) {\n\tstaticSyncer := &staticSyncer{c: c}\n\n\tvar pollInterval time.Duration\n\tpoll := pollIntervalStr != \"\"\n\tif poll {\n\t\tpollInterval, err := types.ToDurationE(pollIntervalStr)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid value for flag poll: %s\", err)","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/hugobuilder.go#L286-L322","documentation":"Once the trace file is created, Hugo calls `trace.Start(f)` from the `runtime/trace` package. This error wraps that failure, which the Go runtime produces when tracing is already in progress in the process. The trace file is not closed here (it is closed later in the stop func).","triggerScenarios":"Occurs when `trace.Start` returns non-nil — almost always because `runtime/trace` is already started by another component in the same process.","commonSituations":"Embedding Hugo in a host application that already started execution tracing; a shared test fixture that calls `trace.Start`; concurrent invocations of the build pipeline within one binary.","solutions":["Stop the other `trace.Start` session before invoking Hugo's `--trace` path.","Run Hugo as its own process so the tracer is not already active.","Do not pass `--trace` when tracing is managed externally."],"exampleFix":"// before\ntrace.Start(f1) // host app still tracing\nhugo.Build(...)  // Hugo then calls trace.Start(f2) -> error\n// after\ntrace.Stop()    // end prior trace first\nhugo.Build(...)","handlingStrategy":"try-catch","validationCode":"// In a host app, ensure only one execution tracer runs.\nvar traceActive bool\nfunc safeStartTrace(f *os.File) error {\n  if traceActive { return fmt.Errorf(\"trace already active\") }\n  if err := trace.Start(f); err != nil { return err }\n  traceActive = true\n  return nil\n}","typeGuard":"null","tryCatchPattern":"err := hugo.Build(cfg)\nif err != nil && strings.Contains(err.Error(), \"failed to start trace\") {\n  // stop the host's active tracer, or drop Hugo's --trace flag and retry\n}","preventionTips":["Run `hugo --trace` in its own process to avoid a double tracer.","Call `trace.Stop()` before any second invocation within one binary.","Keep tracing ownership in a single component."],"tags":["hugo","tracing","runtime","go"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}