{"id":"db7c28bbe9dab6ef","repo":"gohugoio/hugo","slug":"failed-to-create-target-directory-for-q-w","errorCode":null,"errorMessage":"failed to create target directory for %q: %w","messagePattern":"failed to create target directory for %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"create/content.go","lineNumber":196,"sourceCode":"\tfor i, filename := range contentTargetFilenames {\n\t\tif err := b.applyArcheType(filename, b.dirMap.contentFiles[i]); err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\n\t// Copy the rest as is.\n\tfor _, fi := range b.dirMap.otherFiles {\n\t\tmeta := fi.Meta()\n\n\t\tin, err := meta.Open()\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to open non-content file: %w\", err)\n\t\t}\n\t\ttargetFilename := filepath.Join(baseDir, b.targetPath, strings.TrimPrefix(fi.Meta().Filename, b.archetypeFi.Meta().Filename))\n\t\ttargetDir := filepath.Dir(targetFilename)\n\n\t\tif err := b.sourceFs.MkdirAll(targetDir, 0o777); err != nil && !os.IsExist(err) {\n\t\t\treturn fmt.Errorf(\"failed to create target directory for %q: %w\", targetDir, err)\n\t\t}\n\n\t\tout, err := b.sourceFs.Create(targetFilename)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\t_, err = io.Copy(out, in)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\n\t\tin.Close()\n\t\tout.Close()\n\t}\n\n\tb.h.Log.Printf(\"Content dir %q created\", filepath.Join(baseDir, b.targetPath))\n","sourceCodeStart":178,"sourceCodeEnd":214,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/create/content.go#L178-L214","documentation":"Still in the directory-archetype copy loop, Hugo creates the destination directory for a non-content file with MkdirAll before writing the copy. This error means MkdirAll on the source filesystem failed for a reason other than the directory already existing, wrapping the OS error.","triggerScenarios":"contentBuilder.buildDir calling b.sourceFs.MkdirAll(targetDir, 0o777) while copying archetype 'other' files into the new bundle under content/ — failing on permission denied, a read-only filesystem, a path component that exists as a regular file, or disk-full.","commonSituations":"content/ owned by another user (e.g. created by root/Docker) so the current user can't create subdirectories; read-only mounts in CI or containers; a file already existing where a directory is needed (name collision with the bundle path); exhausted disk or quota.","solutions":["Fix ownership/permissions on the content directory tree (e.g. `chown -R $USER content`).","Check no regular file exists at the target directory path shown in the error; rename or remove the conflicting file.","Verify the volume is writable and has free space (common in Docker/CI mounts)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if err := os.MkdirAll(filepath.Dir(target), 0o755); err != nil { return err }","typeGuard":null,"tryCatchPattern":"if err := create.NewContent(...); err != nil {\n    if errors.Is(err, fs.ErrPermission) {\n        // content dir not writable — fix ownership/permissions\n    }\n    return err\n}","preventionTips":["Verify write permissions on the content directory before generating content","Avoid running builds as a different user than the one owning the site tree","Watch for read-only mounts (Docker volumes, CI caches)"],"tags":["hugo","filesystem","permissions","content","bundle"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}