{"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/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/hugobuilder.go#L282-L318","documentation":"Returned by initTraceProfile when os.Create fails for the path given via the --profile-trace flag (c.r.traceprofile). Hugo wraps the OS error so the user can see why the runtime trace output file could not be created.","triggerScenarios":"Running hugo with --profile-trace <path> where os.Create fails: missing parent directory, permission denied, path is a directory, or read-only filesystem.","commonSituations":"Trace path pointing into a directory that doesn't exist, CI/container read-only filesystems, or insufficient permissions on the target directory.","solutions":["Create the parent directory of the --profile-trace path or choose a writable location like ./trace.out.","Check write permissions and read-only mounts.","Avoid pointing the flag at an existing directory."],"exampleFix":"// before\nhugo --profile-trace /var/trace/out.trace\n// after\nhugo --profile-trace ./trace.out","handlingStrategy":"validation","validationCode":"// verify trace output path before enabling --trace\ndir := filepath.Dir(tracePath)\nif fi, err := os.Stat(dir); err != nil || !fi.IsDir() {\n    return fmt.Errorf(\"trace output dir invalid: %v\", err)\n}","typeGuard":"var pathErr *os.PathError\nif errors.As(err, &pathErr) {\n    // path creation failed\n}","tryCatchPattern":"if err := b.build(); err != nil {\n    var pe *os.PathError\n    if errors.As(err, &pe) && strings.Contains(err.Error(), \"trace file\") {\n        // retry without tracing\n    }\n    return err\n}","preventionTips":["Pass an absolute path in a writable directory to the trace flag","Pre-create the output directory","Disable tracing in sandboxed or read-only filesystems"],"tags":["hugo","tracing","filesystem","cli"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}