{"id":"35a12485061ff512","repo":"gohugoio/hugo","slug":"too-short-key-q","errorCode":null,"errorMessage":"too short key: %q","messagePattern":"too short key: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"hugolib/doctree/support.go","lineNumber":114,"sourceCode":"\tctx.eventMu.Lock()\n\tdefer ctx.eventMu.Unlock()\n\tctx.events = append(ctx.events, event)\n}\n\n// StopPropagation stops the propagation of the event.\nfunc (e *Event[T]) StopPropagation() {\n\te.stopPropagation = true\n}\n\n// ValidateKey returns an error if the key is not valid.\nfunc ValidateKey(key string) error {\n\tif key == \"\" {\n\t\t// Root node.\n\t\treturn nil\n\t}\n\n\tif len(key) < 2 {\n\t\treturn fmt.Errorf(\"too short key: %q\", key)\n\t}\n\n\tif key[0] != '/' {\n\t\treturn fmt.Errorf(\"key must start with '/': %q\", key)\n\t}\n\n\tif key[len(key)-1] == '/' {\n\t\treturn fmt.Errorf(\"key must not end with '/': %q\", key)\n\t}\n\n\treturn nil\n}\n\n// Event is used to communicate events in the tree.\ntype Event[T any] struct {\n\tName            string\n\tPath            string\n\tSource          T","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/hugolib/doctree/support.go#L96-L132","documentation":"doctree.ValidateKey enforces the invariant format for keys in Hugo's page/document tree: except for the empty root key, a key must be at least 2 characters (a leading '/' plus at least one character). A key of length 1 (e.g. just \"/\") can't name a real node, so it is rejected to fail fast before corrupting the radix tree.","triggerScenarios":"Calling tree.Insert/InsertIntoValuesDimension (or anything that funnels into ValidateKey) with a one-character key such as \"/\" or \"a\". Typically produced by upstream path normalization emitting \"/\" for a page path instead of the empty root key.","commonSituations":"Mostly an internal-invariant error: seen when developing Hugo itself or embedding hugolib and constructing doctree keys by hand; occasionally surfaces from pathological content paths/mounts that normalize to a bare slash.","solutions":["Pass \"\" (empty string) for the root node, not \"/\".","Ensure key construction produces \"/segment\" style paths — check the normalization step that built the key.","If hit as a Hugo user, report the site layout/mount that triggers it as a bug with a minimal reproducer."],"exampleFix":"// before\ntree.Insert(\"/\", n) // root as \"/\"\n// after\ntree.Insert(\"\", n) // root is the empty key","handlingStrategy":"validation","validationCode":"if len(key) < 2 {\n    return fmt.Errorf(\"invalid tree key %q: too short\", key)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never pass raw user/page paths directly; normalize into a doctree key first (leading '/', no trailing '/')","Validate key length (>= 2, i.e. '/' plus at least one char) at the call boundary","Add unit tests for boundary keys: \"\", \"/\", \"/a\"","Centralize key construction in one helper so all callers produce valid keys"],"tags":["hugo","doctree","validation","invariant"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}