{"record":{"id":"bbe1d049713c6df4","repo":"gohugoio/hugo","slug":"failed-to-read-archetype-file-w","errorCode":null,"errorMessage":"failed to read archetype file: %w","messagePattern":"failed to read archetype file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"create/content.go","lineNumber":388,"sourceCode":"\tif err != nil {\n\t\treturn err\n\t}\n\n\treturn cmd.Run()\n}\n\nfunc (b *contentBuilder) usesSiteVar(fi hugofs.FileMetaInfo) (bool, error) {\n\tif fi == nil {\n\t\treturn false, nil\n\t}\n\tf, err := fi.Meta().Open()\n\tif err != nil {\n\t\treturn false, err\n\t}\n\tdefer f.Close()\n\tbb, err := io.ReadAll(f)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to read archetype file: %w\", err)\n\t}\n\n\treturn bytes.Contains(bb, []byte(\".Site\")) || bytes.Contains(bb, []byte(\"site.\")), nil\n}\n\ntype archetypeMap struct {\n\t// These needs to be parsed and executed as Go templates.\n\tcontentFiles []hugofs.FileMetaInfo\n\t// These are just copied to destination.\n\totherFiles []hugofs.FileMetaInfo\n\t// If the templates needs a fully built site. This can potentially be\n\t// expensive, so only do when needed.\n\tsiteUsed bool\n}\n","sourceCodeStart":370,"sourceCodeEnd":403,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/create/content.go#L370-L403","documentation":"contentBuilder.usesSiteVar (create/content.go:386) opens the archetype file and reads it fully with io.ReadAll to detect whether it references .Site or site. (which decides whether a full site build is needed). This wraps a ReadAll failure on the already-opened archetype file.","triggerScenarios":"The archetype file opens but cannot be read end-to-end: an intermittent IO error, the file truncates or is removed mid-read, or a virtual FS reports a read error.","commonSituations":"Archetype file on a network/flaky mount; file replaced while Hugo is running; corruption on the archetypes volume.","solutions":["Verify the archetype file is readable in full (cat it, checksum it).","Recreate the archetype file from a known-good source.","Move archetypes/ off a flaky/network mount onto local disk."],"exampleFix":"# before: archetypes/default.md is truncated/corrupt\n$ cat archetypes/default.md   # reads partway then errors\n\n# after: rewrite the archetype\n$ cat > archetypes/default.md <<'EOF'\n---\ntitle: \"{{ replace .File.ContentBaseName \"-\" \" \" | title }}\"\ndate: {{ .Date }}\ndraft: true\n---\nEOF","handlingStrategy":"try-catch","validationCode":"// Read-check the archetype file before NewContent.\nfunc ValidateArchetypeReadable(fs afero.Fs, path string) error {\n    f, err := fs.Open(path)\n    if err != nil { return err }\n    defer f.Close()\n    if _, err := io.ReadAll(f); err != nil { return err }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"if err := create.NewContent(h, kind, targetPath, force); err != nil {\n    return err\n}","preventionTips":["Keep archetype files readable and intact.","Avoid editing archetype files while Hugo is running.","Move archetypes off network mounts for reliability."],"tags":["archetype","filesystem"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}