{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/hugobuilder.go#L286-L322","documentation":"Returned by initTraceProfile when runtime/trace.Start(f) fails after the trace file was created. trace.Start errors when tracing is already enabled for the process; Hugo wraps and returns it. Note the file is not closed on this path.","triggerScenarios":"trace.Start returning non-nil, i.e. a runtime execution trace is already active in the process (double start), since file creation already succeeded.","commonSituations":"Essentially only when embedding Hugo in a program that already started runtime tracing, or invoking the profiling init path twice.","solutions":["Ensure runtime tracing is started only once per process; remove any competing trace.Start call in an embedding program.","Rerun without --profile-trace to continue the build while investigating."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// runtime/trace allows only one active trace per process;\n// ensure your host program isn't already tracing","typeGuard":null,"tryCatchPattern":"if err := b.build(); err != nil {\n    if strings.Contains(err.Error(), \"start trace\") {\n        trace.Stop() // stop any host-owned trace, then rerun without the flag\n    }\n    return err\n}","preventionTips":["Don't combine Hugo's --trace with runtime/trace.Start in the embedding process","Only one execution trace can be active per process","Treat trace failures as non-fatal: log and continue the build without tracing"],"tags":["hugo","tracing","runtime","go"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}