{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/create/content.go#L178-L214","documentation":"During the directory-archetype copy (create/content.go:195), Hugo does sourceFs.MkdirAll(targetDir, 0o777) for each copied file, ignoring only the 'already exists' case. This wraps any other MkdirAll failure (permission denied, read-only fs, disk full, invalid/over-long path).","triggerScenarios":"The resolved target directory cannot be created: content root on a read-only mount, no free disk space/inodes, a path segment not writable, invalid characters or excessive length in the path.","commonSituations":"CI checkout mounted read-only; running on a scratch container with a small tmpfs; path with spaces/unicode that the FS rejects; sandbox blocking writes outside the project.","solutions":["Confirm write permission on the content root and all parent directories of the target.","Free disk space / inodes if the volume is full.","Shorten or simplify the target path to avoid FS limits.","Run Hugo from a writable working directory rather than a read-only checkout."],"exampleFix":"# before\n$ hugo new posts/$(printf 'a%.0s' {1..300}).md  # path too long\n\n# after\n$ hugo new posts/short-title.md","handlingStrategy":"validation","validationCode":"// Ensure the target directory can be created before scaffolding.\nfunc ValidateTargetDirWritable(fs afero.Fs, dir string) error {\n    probe := filepath.Join(dir, \".hugo-write-probe\")\n    if err := fs.MkdirAll(dir, 0o777); err != nil && !os.IsExist(err) {\n        return err\n    }\n    _ = fs.Remove(probe)\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := create.NewContent(h, kind, targetPath, force); err != nil {\n    return err\n}","preventionTips":["Run Hugo from a writable working directory.","Keep content paths reasonably short and free of problematic characters.","Check disk space/inodes before bulk scaffolding."],"tags":["filesystem","permissions","content"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}