{"record":{"id":"5dedd5d1e1ca890f","repo":"gohugoio/hugo","slug":"alignx-must-be-one-of-left-center-right","errorCode":null,"errorMessage":"alignx must be one of left, center, right","messagePattern":"alignx must be one of left, center, right","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/images/filters.go","lineNumber":104,"sourceCode":"\tvar opt hmaps.Params\n\tif len(options) > 0 {\n\t\topt = hmaps.MustToParamsAndPrepare(options[0])\n\t\tfor option, v := range opt {\n\t\t\tswitch option {\n\t\t\tcase \"color\":\n\t\t\t\tif color, ok, _ := toColorGo(v); ok {\n\t\t\t\t\ttf.color = color\n\t\t\t\t}\n\t\t\tcase \"size\":\n\t\t\t\ttf.size = cast.ToFloat64(v)\n\t\t\tcase \"x\":\n\t\t\t\ttf.x = cast.ToInt(v)\n\t\t\tcase \"y\":\n\t\t\t\ttf.y = cast.ToInt(v)\n\t\t\tcase \"alignx\":\n\t\t\t\ttf.alignx = cast.ToString(v)\n\t\t\t\tif tf.alignx != \"left\" && tf.alignx != \"center\" && tf.alignx != \"right\" {\n\t\t\t\t\tpanic(\"alignx must be one of left, center, right\")\n\t\t\t\t}\n\t\t\tcase \"aligny\":\n\t\t\t\ttf.aligny = cast.ToString(v)\n\t\t\t\tif tf.aligny != \"top\" && tf.aligny != \"center\" && tf.aligny != \"bottom\" {\n\t\t\t\t\tpanic(\"aligny must be one of top, center, bottom\")\n\t\t\t\t}\n\n\t\t\tcase \"linespacing\":\n\t\t\t\ttf.linespacing = cast.ToInt(v)\n\t\t\tcase \"font\":\n\t\t\t\tif err, ok := v.(error); ok {\n\t\t\t\t\tpanic(fmt.Sprintf(\"invalid font source: %s\", err))\n\t\t\t\t}\n\t\t\t\tfontSource, ok1 := v.(hugio.ReadSeekCloserProvider)\n\t\t\t\tidentifier, ok2 := v.(resource.Identifier)\n\n\t\t\t\tif !(ok1 && ok2) {\n\t\t\t\t\tpanic(fmt.Sprintf(\"invalid text font source: %T\", v))","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/images/filters.go#L86-L122","documentation":"Panic while building a Text image filter (images.Text): the 'alignx' option was set to a value other than 'left', 'center', or 'right'. The Text filter draws text onto an image and alignx controls horizontal alignment; only those three strings are valid. This is a template/Go usage error at filter-construction time.","triggerScenarios":"Calling {{ $images.Text \"hello\" (dict \"alignx\" \"middle\") }} or constructing images.Text with alignx set to an invalid string (e.g. 'top', 'middle', 'start', 'centre'). The panic fires immediately while the filter options are parsed, before any image processing.","commonSituations":"Template author confuses alignx with aligny or uses CSS-like values ('flex-start', 'justify'). Typos ('centre', 'lef'). Translating from another tool's alignment vocabulary.","solutions":["Set alignx to exactly one of \"left\", \"center\", or \"right\".","Use aligny (top/center/bottom) for vertical alignment instead.","If the value comes from front matter, validate/whitelist it before passing to the filter."],"exampleFix":"{{/* before */}}\n{{ $f := $images.Text \"Hello\" (dict \"alignx\" \"middle\") }}\n\n{{/* after */}}\n{{ $f := $images.Text \"Hello\" (dict \"alignx\" \"center\") }}\n{{/* for vertical use aligny */}} {{ $images.Text \"Hi\" (dict \"aligny\" \"middle\" | replace ... ) }}\n{{/* note: aligny valid values are top, center, bottom */}}","handlingStrategy":"type-guard","validationCode":"// Whitelist alignx before building the Text filter.\n// Template:  {{ $align := \"center\" }} {{ if not (in (slice \"left\" \"center\" \"right\") $align) }}{{ $align = \"left\" }}{{ end }}","typeGuard":"func validAlignX(v string) string {\n    switch v {\n    case \"left\", \"center\", \"right\":\n        return v\n    }\n    return \"left\" // safe default\n}\n\n// Usage: opts[\"alignx\"] = validAlignX(opts[\"alignx\"].(string))","tryCatchPattern":null,"preventionTips":["Use only \"left\", \"center\", \"right\" for alignx.","Use aligny (top/center/bottom) for vertical alignment.","Validate front-matter-supplied alignment strings against a whitelist.","Remember alignx is horizontal, aligny is vertical."],"tags":["images","filters","templates","panic","api-misuse"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}