gohugoio/hugo · error
failed to start trace: %w
Error message
failed to start trace: %w
What it means
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.
Source
Thrown at commands/hugobuilder.go:304
if stopMemTicker != nil {
stopMemTicker()
}
}, nil
}
func (c *hugoBuilder) initTraceProfile() (func(), error) {
if c.r.traceprofile == "" {
return nil, nil
}
f, err := os.Create(c.r.traceprofile)
if err != nil {
return nil, fmt.Errorf("failed to create trace file: %w", err)
}
if err := trace.Start(f); err != nil {
return nil, fmt.Errorf("failed to start trace: %w", err)
}
return func() {
trace.Stop()
f.Close()
}, nil
}
// newWatcher creates a new watcher to watch filesystem events.
func (c *hugoBuilder) newWatcher(pollIntervalStr string, dirList ...string) (*watcher.Batcher, error) {
staticSyncer := &staticSyncer{c: c}
var pollInterval time.Duration
poll := pollIntervalStr != ""
if poll {
pollInterval, err := types.ToDurationE(pollIntervalStr)
if err != nil {
return nil, fmt.Errorf("invalid value for flag poll: %s", err)View on GitHub ↗ (pinned to 8a468df065)
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.
Defensive patterns
Strategy: try-catch
Validate before calling
// runtime/trace allows only one active trace per process; // ensure your host program isn't already tracing
Try / catch
if err := b.build(); err != nil {
if strings.Contains(err.Error(), "start trace") {
trace.Stop() // stop any host-owned trace, then rerun without the flag
}
return err
} Prevention
- 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
When it happens
Trigger: trace.Start returning non-nil, i.e. a runtime execution trace is already active in the process (double start), since file creation already succeeded.
Common situations: Essentially only when embedding Hugo in a program that already started runtime tracing, or invoking the profiling init path twice.
Related errors
- errConfigNotSet
- failed to start CPU profile: %w
- failed to create trace file: %w
- failed to compile cache buster target %q: %w
- failed to compile whitelist pattern %q: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/13d84285d9d7b975.json.
Report an issue: GitHub ↗.