{"id":"9254f5c7e01d7c71","repo":"gohugoio/hugo","slug":"version-name-cannot-be-empty","errorCode":null,"errorMessage":"version name cannot be empty","messagePattern":"version name cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/versions/versions.go","lineNumber":165,"sourceCode":"const defaultContentVersionFallback = \"v1.0.0\"\n\nfunc (r *VersionsInternal) init(defaultContentVersion string) error {\n\tif r.versionConfigs == nil {\n\t\tr.versionConfigs = make(map[string]VersionConfig)\n\t}\n\tdefaultContentVersionProvided := defaultContentVersion != \"\"\n\tif len(r.versionConfigs) == 0 {\n\t\tif defaultContentVersion == \"\" {\n\t\t\tdefaultContentVersion = defaultContentVersionFallback\n\t\t}\n\t\t// Add a default version.\n\t\tr.versionConfigs[defaultContentVersion] = VersionConfig{}\n\t}\n\n\tvar defaultSeen bool\n\tfor k, v := range r.versionConfigs {\n\t\tif k == \"\" {\n\t\t\treturn errors.New(\"version name cannot be empty\")\n\t\t}\n\t\tif err := paths.ValidateIdentifier(k); err != nil {\n\t\t\treturn fmt.Errorf(\"version name %q is invalid: %s\", k, err)\n\t\t}\n\n\t\tvar isDefault bool\n\t\tif k == defaultContentVersion {\n\t\t\tisDefault = true\n\t\t\tdefaultSeen = true\n\t\t}\n\n\t\t// Ignore error, this may not be a semver version.\n\t\tparsedVersion, _ := version.ParseVersion(k)\n\n\t\tr.Sorted = append(r.Sorted, VersionInternal{Name: k, parsedVersion: parsedVersion, Default: isDefault, VersionConfig: v})\n\t}\n\n\t// Sort by weight if set, then semver descending.","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/versions/versions.go#L147-L183","documentation":"Raised while initializing the content versions config (hugolib/versions/versions.go:165) when a key in the versions map is the empty string. Every version must have a non-empty name because the name becomes a path identifier and the map key for version configs.","triggerScenarios":"A versions/versionConfigs map in site config containing an empty-string key — e.g. a YAML/TOML versions block with a blank key or an entry defined as \"\": {...}.","commonSituations":"Hand-edited YAML where a list/map entry lost its key, templated config generation emitting an empty version name, or converting config formats and dropping a key. This is a newer versioned-content feature, so misreading its docs while adopting it is common.","solutions":["Find the empty key in your versions config block and give it a real name (e.g. \"v1.0.0\").","Remove the malformed entry if it was accidental.","Validate generated config (hugo config) if the versions block is produced by tooling."],"exampleFix":"# before (hugo.yaml)\nversions:\n  \"\": {}\n  v2: {}\n# after\nversions:\n  v1: {}\n  v2: {}","handlingStrategy":"validation","validationCode":"for _, v := range versionsConfig {\n    if strings.TrimSpace(v.Name) == \"\" {\n        return fmt.Errorf(\"version entry missing name\")\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Require a non-empty name field for every entry in the versions config","Validate config generated by scripts before feeding it to Hugo","Add a CI schema check on the versions section of site config"],"tags":["hugo","config","versions","validation"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}