{"record":{"id":"786f247910b5f6c7","repo":"gohugoio/hugo","slug":"initsites-w","errorCode":null,"errorMessage":"initSites: %w","messagePattern":"initSites: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites_build.go","lineNumber":162,"sourceCode":"\t}\n\n\tvar prepareErr error\n\n\tif !config.PartialReRender {\n\t\tprepare := func() error {\n\t\t\tinit := func(conf *BuildCfg) error {\n\t\t\t\tfor _, s := range h.Sites {\n\t\t\t\t\ts.Deps.BuildStartListeners.Notify()\n\t\t\t\t}\n\n\t\t\t\tif len(events) > 0 || len(conf.WhatChanged.Changes()) > 0 {\n\t\t\t\t\t// Rebuild\n\t\t\t\t\tif err := h.initRebuild(conf); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"initRebuild: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tif err := h.initSites(); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"initSites: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\treturn nil\n\t\t\t}\n\n\t\t\tctx := context.Background()\n\n\t\t\tif err := h.process(ctx, infol, conf, init, events...); err != nil {\n\t\t\t\treturn fmt.Errorf(\"process: %w\", err)\n\t\t\t}\n\t\t\th.reportProgress(func() (state terminal.ProgressState, progress float64) {\n\t\t\t\treturn terminal.ProgressNormal, 0.15\n\t\t\t})\n\t\t\tif err := h.assemble(ctx, infol, conf); err != nil {\n\t\t\t\treturn fmt.Errorf(\"assemble: %w\", err)\n\t\t\t}\n\t\t\th.reportProgress(func() (state terminal.ProgressState, progress float64) {","sourceCodeStart":144,"sourceCodeEnd":180,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites_build.go#L144-L180","documentation":"Wraps a failure of initSites() during a full (non-rebuild) build. initSites() calls h.reset() to clear build state; the wrapper surfaces any error from that reset/init step.","triggerScenarios":"Raised at hugo_sites_build.go:162 when h.initSites() returns an error during the initial build path (no file events / no WhatChanged). Typically rare since initSites mainly resets state.","commonSituations":"Custom Hugo integration where reset() encounters inconsistent state; a Hugo internal panic-like condition during site teardown; concurrent mutation of HugoSites during init in an embedded host.","solutions":["Unwrap the %w to find the concrete reset/init failure.","Avoid sharing/mutating a HugoSites instance across goroutines during Build.","Re-create the HugoSites (hugo.NewHugoSites) fresh instead of reusing a tainted instance.","Reproduce with a minimal config and bisect templates/modules if internal state is suspected."],"exampleFix":"// before: reuse tainted sites across builds\nhs.Build(cfg1)\n// later...\nhs.Build(cfg2)  // initSites fails on dirty state\n\n// after: rebuild sites fresh\nhs, _ = hugo.NewHugoSites(d1)\nhs.Build(cfg2)","handlingStrategy":"try-catch","validationCode":"// Reuse a HugoSites instance only between successful builds; rebuild fresh after a failure.\nif lastBuildFailed { hs, _ = hugo.NewHugoSites(deps) }","typeGuard":null,"tryCatchPattern":"if err := h.initSites(); err != nil {\n    // recreate sites rather than reuse a half-reset instance\n    h, _ = hugo.NewHugoSites(h.Deps)\n    return fmt.Errorf(\"initSites: %w\", err)\n}","preventionTips":["Never share HugoSites across goroutines during a build.","Recreate HugoSites after any error rather than reusing tainted state.","Keep integrations updated to the current Build API."],"tags":["build","initialization","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}