{"id":"fedd72298e7d115d","repo":"gohugoio/hugo","slug":"failed-to-create-workingdir-w","errorCode":null,"errorMessage":"failed to create workingDir: %w","messagePattern":"failed to create workingDir: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/commandeer.go","lineNumber":261,"sourceCode":"\t}\n\tr.resolveEnvironment(false)\n\tcc, _, err := r.commonConfigs.GetOrCreate(key, func(key configKey) (*commonConfig, error) {\n\t\tvar dir string\n\t\tif r.source != \"\" {\n\t\t\tdir, _ = filepath.Abs(r.source)\n\t\t} else {\n\t\t\tdir, _ = os.Getwd()\n\t\t}\n\n\t\tif cfg == nil {\n\t\t\tcfg = config.New()\n\t\t}\n\n\t\tif !cfg.IsSet(\"workingDir\") {\n\t\t\tcfg.Set(\"workingDir\", dir)\n\t\t} else {\n\t\t\tif err := os.MkdirAll(cfg.GetString(\"workingDir\"), 0o777); err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to create workingDir: %w\", err)\n\t\t\t}\n\t\t}\n\n\t\t// Load the config first to allow publishDir to be configured in config file.\n\t\tconfigs, err := allconfig.LoadConfig(\n\t\t\tallconfig.ConfigSourceDescriptor{\n\t\t\t\tFlags:                    cfg,\n\t\t\t\tFs:                       hugofs.Os,\n\t\t\t\tFilename:                 r.cfgFile,\n\t\t\t\tConfigDir:                r.cfgDir,\n\t\t\t\tEnvironment:              r.environment,\n\t\t\t\tLogger:                   r.logger,\n\t\t\t\tIgnoreModuleDoesNotExist: key.ignoreModulesDoesNotExists,\n\t\t\t\tSkipNpmCheck:             key.skipNpmCheck,\n\t\t\t},\n\t\t)\n\t\tif err != nil {\n\t\t\treturn nil, err","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/commandeer.go#L243-L279","documentation":"Emitted in `rootCommand` config setup when a `workingDir` was explicitly set (via flag `-s/--source` or config) and `os.MkdirAll(workingDir, 0o777)` fails. Hugo creates the working directory if it doesn't exist; an OS-level failure creating it (permissions, invalid path, file in the way) aborts config initialization with this wrapped error.","triggerScenarios":"Running any Hugo command with `workingDir` set in config or via flags to a path that cannot be created: a parent directory that is read-only, a path component that is an existing regular file, or an invalid path on the OS.","commonSituations":"CI containers running as non-root pointing `--source` at a root-owned location; `workingDir` set in config with a typo or a Windows-invalid path; mounting issues in Docker where the target isn't writable.","solutions":["Check the wrapped OS error; fix permissions on the parent directory or choose a writable workingDir.","Verify no regular file exists at the workingDir path or one of its parents.","In CI/Docker, ensure the volume mount is writable by the running user or pre-create the directory with correct ownership."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Resolve and probe the working dir before constructing the commandeer\nabs, err := filepath.Abs(workingDir)\nif err != nil {\n    return err\n}\nif err := os.MkdirAll(abs, 0o755); err != nil {\n    return fmt.Errorf(\"cannot create working dir %q: %w\", abs, err)\n}","typeGuard":null,"tryCatchPattern":"if err := run(); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        // pick a user-writable --source / -s directory\n    }\n    return err\n}","preventionTips":["Pass an absolute, user-writable path to --source","Don't run hugo inside directories that may be deleted concurrently (temp cleanup, CI workspaces)","Check parent-directory permissions when running under restrictive umasks or containers"],"tags":["hugo","config","filesystem","permissions","working-dir"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}