{"record":{"id":"536b67bd03d7397d","repo":"gohugoio/hugo","slug":"the-configured-defaultcontentrole-q-does-not-exis","errorCode":null,"errorMessage":"the configured defaultContentRole %q does not exist","messagePattern":"the configured defaultContentRole %q does not exist","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/roles/roles.go","lineNumber":183,"sourceCode":"\n\t// Sort by weight if set, then by name.\n\tsort.SliceStable(r.Sorted, func(i, j int) bool {\n\t\tri, rj := r.Sorted[i], r.Sorted[j]\n\t\tif ri.Weight == rj.Weight {\n\t\t\treturn ri.Name < rj.Name\n\t\t}\n\t\tif rj.Weight == 0 {\n\t\t\treturn true\n\t\t}\n\t\tif ri.Weight == 0 {\n\t\t\treturn false\n\t\t}\n\t\treturn ri.Weight < rj.Weight\n\t})\n\n\tif !defaultSeen {\n\t\tif defaultContentRoleProvided {\n\t\t\treturn \"\", fmt.Errorf(\"the configured defaultContentRole %q does not exist\", defaultContentRole)\n\t\t}\n\t\t// If no default role is set, we set the first one.\n\t\tfirst := r.Sorted[0]\n\t\tfirst.Default = true\n\t\tr.roleConfigs[first.Name] = first.RoleConfig\n\t\tr.Sorted[0] = first\n\t\tdefaultContentRole = first.Name\n\t}\n\n\treturn defaultContentRole, nil\n}\n\nfunc (r RolesInternal) Has(role string) bool {\n\t_, found := r.roleConfigs[role]\n\treturn found\n}\n\nfunc DecodeConfig(defaultContentRole string, m map[string]any) (*config.ConfigNamespace[map[string]RoleConfig, RolesInternal], string, error) {","sourceCodeStart":165,"sourceCodeEnd":201,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/hugolib/roles/roles.go#L165-L201","documentation":"Raised by RolesInternal.init (roles.go:183) when defaultContentRole is explicitly provided in config but does not match any key in the roleConfigs map. The default role must be one of the declared roles; if `defaultSeen` is false after iterating and the user supplied a default, this fires.","triggerScenarios":"Setting `defaultContentRole = \"main\"` while the roles map only contains `editor` and `guest`; a typo in the default role name; renaming a role without updating the default reference.","commonSituations":"Refactoring role names and forgetting the default; mismatched casing (default set to `Editor` while key is `editor` — note identifiers must be lowercase anyway); copying config between projects with different role sets.","solutions":["Set defaultContentRole to an existing role key, or omit it so Hugo auto-picks the first role.","Fix typos and casing — the value must exactly match a declared role key.","If you removed the intended default role, choose a new one or delete the defaultContentRole setting."],"exampleFix":"# before\n[roles]\n  [roles.editor]\n    weight = 1\ndefaultContentRole = \"main\"\n\n# after\ndefaultContentRole = \"editor\"","handlingStrategy":"validation","validationCode":"# Ensure defaultContentRole exists among declared role keys.\nroles=$(awk '/^\\[roles\\./ {gsub(/\\[roles\\.|\\]/,\"\"); print}' hugo.toml | sort -u)\ndefault=$(awk -F= '/defaultContentRole/ {gsub(/[ \"]/,\"\",$2); print $2}' hugo.toml)\necho \"$roles\" | grep -qx \"$default\" || echo \"default '$default' not declared\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Either omit defaultContentRole (Hugo auto-selects the first role) or set it to an existing key.","When renaming a role, update defaultContentRole in the same commit.","Validate role/default consistency in CI."],"tags":["roles","configuration","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}