{"id":"a64e14d75eec3e08","repo":"gohugoio/hugo","slug":"conf-must-be-set","errorCode":null,"errorMessage":"conf must be set","messagePattern":"conf must be set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"commands/commandeer.go","lineNumber":358,"sourceCode":"\t\t\tfs.PublishDir = hugofs.NewCreateCountingFs(fs.PublishDir)\n\t\t}\n\n\t\tcommonConfig := &commonConfig{\n\t\t\tmu:      &sync.Mutex{},\n\t\t\tconfigs: configs,\n\t\t\tcfg:     cfg,\n\t\t\tfs:      fs,\n\t\t}\n\n\t\treturn commonConfig, nil\n\t})\n\n\treturn cc, err\n}\n\nfunc (r *rootCommand) HugFromConfig(conf *commonConfig) (*hugolib.HugoSites, error) {\n\tif conf == nil {\n\t\treturn nil, fmt.Errorf(\"conf must be set\")\n\t}\n\tk := configKey{counter: r.configVersionID.Load()}\n\th, _, err := r.hugoSites.GetOrCreate(k, func(key configKey) (*hugolib.HugoSites, error) {\n\t\tdepsCfg := r.newDepsConfig(conf)\n\t\treturn hugolib.NewHugoSites(depsCfg)\n\t})\n\treturn h, err\n}\n\nfunc (r *rootCommand) Hugo(cfg config.Provider) (*hugolib.HugoSites, error) {\n\treturn r.getOrCreateHugo(cfg, false)\n}\n\nfunc (r *rootCommand) getOrCreateHugo(cfg config.Provider, ignoreModuleDoesNotExist bool) (*hugolib.HugoSites, error) {\n\tk := configKey{counter: r.configVersionID.Load(), ignoreModulesDoesNotExists: ignoreModuleDoesNotExist}\n\th, _, err := r.hugoSites.GetOrCreate(k, func(key configKey) (*hugolib.HugoSites, error) {\n\t\tconf, err := r.ConfigFromProvider(key, cfg)\n\t\tif err != nil {","sourceCodeStart":340,"sourceCodeEnd":376,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/commands/commandeer.go#L340-L376","documentation":"Returned by `rootCommand.HugFromConfig` when called with a nil `*commonConfig`. It is a fail-fast guard: building a `HugoSites` object requires a loaded configuration, and a nil conf indicates a programming error earlier in the command flow (config load skipped or its error ignored), not a user mistake.","triggerScenarios":"Internal Hugo code (or code embedding the commands package) calling `HugFromConfig(nil)` — typically because a preceding `ConfigFromProvider`/config-load step failed and its result was used anyway.","commonSituations":"Seen mostly during Hugo development or when a command's init path is refactored and forgets to propagate the config-load error; end users would normally see the underlying config error instead.","solutions":["Find where the commonConfig was produced and surface the original config-loading error instead of passing nil onward.","If embedding Hugo, ensure you call the config-loading path and check its error before requesting HugoSites.","Report as a Hugo bug if you hit it from a stock CLI invocation, including the exact command."],"exampleFix":"// before\nconf, _ := r.ConfigFromProvider(k, cfg)\nh, err := r.HugFromConfig(conf)\n// after\nconf, err := r.ConfigFromProvider(k, cfg)\nif err != nil { return err }\nh, err := r.HugFromConfig(conf)","handlingStrategy":"validation","validationCode":"// Programmatic use: never pass a nil config into the deps/commandeer setup\nif conf == nil {\n    return errors.New(\"load config first: allconfig.LoadConfig(...)\")\n}","typeGuard":"func hasConfig(c *commonConfig) bool { return c != nil && c.configs != nil }","tryCatchPattern":null,"preventionTips":["Always load configuration (config loader) before constructing site/deps objects","In library embedding, enforce ordering via a constructor that requires the config argument","Treat this as a programmer error (invariant violation), not a runtime condition to retry"],"tags":["hugo","internal","nil-guard","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}