{"record":{"id":"b75b6dfac618f090","repo":"gohugoio/hugo","slug":"initrebuild-w","errorCode":null,"errorMessage":"initRebuild: %w","messagePattern":"initRebuild: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/hugo_sites_build.go","lineNumber":158,"sourceCode":"\tconf := &config\n\tif conf.WhatChanged == nil {\n\t\t// Assume everything has changed\n\t\tconf.WhatChanged = &WhatChanged{needsPagesAssembly: true}\n\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})","sourceCodeStart":140,"sourceCodeEnd":176,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/hugo_sites_build.go#L140-L176","documentation":"Wraps a failure of initRebuild() during a rebuild triggered by file events or remote changes. initRebuild resets build state for all sites; failure here means the rebuild preconditions are wrong (e.g. not in watch mode).","triggerScenarios":"Raised at hugo_sites_build.go:158 when h.initRebuild(conf) errors — most commonly 'rebuild called when not in watch mode' (hugo_sites_build.go:263) if a rebuild path is invoked without Internal.Watch set.","commonSituations":"A single-page/partial-rebuild API path called when the site was not initialized for watching; a custom integration invoking Build with WhatChanged.Changes() populated but watch disabled; misconfigured hugo server lifecycle.","solutions":["If you invoke rebuilds programmatically, ensure Configs.Base.Internal.Watch is true (start a watcher first).","For one-off builds, don't pass WhatChanged — use a full build path instead.","When using `hugo server`, confirm it started successfully before file events arrive.","Update Hugo to a version matching your integration's rebuild API expectations."],"exampleFix":"// before: rebuild without watch enabled\nh.Build(&BuildCfg{WhatChanged: &WhatChanged{needsPagesAssembly: true}})\n// -> initRebuild: rebuild called when not in watch mode\n\n// after: enable watch before rebuild\ncfg.Base.Internal.Watch = true\nh.Build(&BuildCfg{WhatChanged: &WhatChanged{needsPagesAssembly: true}})","handlingStrategy":"validation","validationCode":"// Only request a rebuild when watch is enabled.\nif !h.Configs.Base.Internal.Watch { return errors.New(\"enable watch before rebuild\") }","typeGuard":null,"tryCatchPattern":"if err := h.initRebuild(conf); err != nil {\n    if strings.Contains(err.Error(), \"not in watch mode\") {\n        // fall back to a full build\n        return h.initSites()\n    }\n    return fmt.Errorf(\"initRebuild: %w\", err)\n}","preventionTips":["When embedding Hugo, set Internal.Watch=true before issuing rebuilds.","Don't pass WhatChanged for one-off full builds.","Ensure `hugo server` has fully started before relying on rebuilds."],"tags":["build","rebuild","watch","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}