{"record":{"id":"6098930f21aea9ad","repo":"gohugoio/hugo","slug":"failed-to-read-archetype-file-q-s-w","errorCode":null,"errorMessage":"failed to read archetype file %q: %s: %w","messagePattern":"failed to read archetype file %q: (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/content_factory.go","lineNumber":53,"sourceCode":"// ContentFactory creates content files from archetype templates.\ntype ContentFactory struct {\n\th *HugoSites\n\n\t// We parse the archetype templates as Go templates, so we need\n\t// to replace any shortcode with a temporary placeholder.\n\tshortcodeReplacerPre  *strings.Replacer\n\tshortcodeReplacerPost *strings.Replacer\n}\n\n// ApplyArchetypeFilename archetypeFilename to w as a template using the given Page p as the foundation for the data context.\nfunc (f ContentFactory) ApplyArchetypeFi(w io.Writer, p page.Page, archetypeKind string, fi hugofs.FileMetaInfo) error {\n\tif fi.IsDir() {\n\t\treturn fmt.Errorf(\"archetype directory (%q) not supported\", fi.Meta().Filename)\n\t}\n\n\ttemplateSource, err := fi.Meta().ReadAll()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to read archetype file %q: %s: %w\", fi.Meta().Filename, err, err)\n\t}\n\n\treturn f.ApplyArchetypeTemplate(w, p, archetypeKind, string(templateSource))\n}\n\n// ApplyArchetypeTemplate templateSource to w as a template using the given Page p as the foundation for the data context.\nfunc (f ContentFactory) ApplyArchetypeTemplate(w io.Writer, p page.Page, archetypeKind, templateSource string) error {\n\tps := p.(*pageState)\n\tif archetypeKind == \"\" {\n\t\tarchetypeKind = p.Type()\n\t}\n\n\td := &archetypeFileData{\n\t\tType: archetypeKind,\n\t\tDate: htime.Now().Format(time.RFC3339),\n\t\tPage: p,\n\t\tFile: p.File(),\n\t}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/content_factory.go#L35-L71","documentation":"Returned by ApplyArchetypeFi when fi.Meta().ReadAll() fails reading the archetype file's bytes. The wrapped chain redundantly includes the error twice (%s then %w) so the message shows both the formatted and unwrapped form. Reading happens after the IsDir check passed, so the file existed as a file but could not be read.","triggerScenarios":"The archetype file exists but ReadAll errors — permission denied reading it, file truncated/removed between Stat and ReadAll, encoding issue, or a backing fs whose Open/Read fails. Triggered during `hugo new` and any ApplyArchetypeFi caller.","commonSituations":"archetypes/*.md file with restrictive perms (e.g. committed with 600 owned by another user); archetype lives on a mount that dropped; file replaced mid-operation by a sync tool; broken symlink archetype.","solutions":["Check read permission on the archetype file named in the error and chmod/chown as needed.","Confirm the archetype file is a regular file, not a broken symlink.","Re-read after any sync/generation step that may have been mid-write.","If the archetype is on a custom mount, verify the mount source is healthy."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"f, err := os.Open(archetypePath)\nif err != nil { /* preflight read-permission check */ }\ndefer f.Close()\nif _, err := f.Stat(); err != nil { /* not a readable regular file */ }","typeGuard":null,"tryCatchPattern":"if err := cf.ApplyArchetypeFi(w, p, kind, fi); err != nil {\n    if strings.Contains(err.Error(), \"failed to read archetype file\") { /* check perms, then retry */ }\n}","preventionTips":["Verify archetype files are world-readable in the repo (avoid committing 600).","Ensure archetype files are regular files, not broken symlinks.","Pause sync tools that rewrite archetypes mid-build."],"tags":["archetype","io","permissions","content-factory","hugolib"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}