{"record":{"id":"b6617a7d5b1b8d8f","repo":"gohugoio/hugo","slug":"failed-to-create-trace-file-w","errorCode":null,"errorMessage":"failed to create trace file: %w","messagePattern":"failed to create trace file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/hugobuilder.go","lineNumber":300,"sourceCode":"\n\t\tif stopTraceProf != nil {\n\t\t\tstopTraceProf()\n\t\t}\n\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 != \"\"","sourceCodeStart":282,"sourceCodeEnd":318,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/commands/hugobuilder.go#L282-L318","documentation":"Hugo's `hugoBuilder.initTraceProfile` calls `os.Create(c.r.traceprofile)` to open the file for an execution tracer capture (set via `--trace`). This wraps the OS-level failure to create that file, before `trace.Start` is ever called.","triggerScenarios":"Fires when `c.r.traceprofile != \"\"` and `os.Create` fails — missing parent directory, unwritable location, or insufficient permissions on the target path.","commonSituations":"Passing `--trace` with a path whose directory doesn't exist; running Hugo in a container or CI where the cwd is read-only; a relative path resolved against an unexpected working directory.","solutions":["Create and confirm write access to the parent directory, then re-run with an absolute `--trace` path.","Switch to a writable temp directory such as `/tmp/hugo-trace.out`.","Drop `--trace` if you do not need the execution trace."],"exampleFix":"// before\n// $ hugo --trace=/opt/traces/trace.out   (dir absent)\n// after\n// $ mkdir -p /tmp/traces && hugo --trace=/tmp/traces/trace.out","handlingStrategy":"validation","validationCode":"func validateTracePath(p string) error {\n  dir := filepath.Dir(p)\n  if _, err := os.Stat(dir); err != nil { return err }\n  f, err := os.CreateTemp(dir, \".hugotrace-*\")\n  if err != nil { return err }\n  f.Close(); os.Remove(f.Name())\n  return nil\n}","typeGuard":"null","tryCatchPattern":"null","preventionTips":["Use an absolute `--trace` path in a writable temp directory.","Confirm the parent directory exists before invoking Hugo.","Omit `--trace` unless you actively need an execution trace."],"tags":["hugo","tracing","filesystem","go"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}