{"record":{"id":"017ee1141d3d70dc","repo":"gohugoio/hugo","slug":"ellipsis-must-be-a-string","errorCode":null,"errorMessage":"ellipsis must be a string","messagePattern":"ellipsis must be a string","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/strings/truncate.go","lineNumber":62,"sourceCode":"func (ns *Namespace) Truncate(s any, options ...any) (template.HTML, error) {\n\tlength, err := cast.ToIntE(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\tvar textParam any\n\tvar ellipsis string\n\n\tswitch len(options) {\n\tcase 0:\n\t\treturn \"\", errors.New(\"truncate requires a length and a string\")\n\tcase 1:\n\t\ttextParam = options[0]\n\t\tellipsis = \" …\"\n\tcase 2:\n\t\ttextParam = options[1]\n\t\tellipsis, err = cast.ToStringE(options[0])\n\t\tif err != nil {\n\t\t\treturn \"\", errors.New(\"ellipsis must be a string\")\n\t\t}\n\t\tif _, ok := options[0].(template.HTML); !ok {\n\t\t\tellipsis = html.EscapeString(ellipsis)\n\t\t}\n\tdefault:\n\t\treturn \"\", errors.New(\"too many arguments passed to truncate\")\n\t}\n\n\ttext, err := cast.ToStringE(textParam)\n\tif err != nil {\n\t\treturn \"\", errors.New(\"text must be a string\")\n\t}\n\n\t_, isHTML := textParam.(template.HTML)\n\n\tif utf8.RuneCountInString(text) <= length {\n\t\tif isHTML {\n\t\t\treturn template.HTML(text), nil","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/strings/truncate.go#L44-L80","documentation":"Thrown by strings.Truncate when two options are supplied and the first (the ellipsis) cannot be cast to a string (tpl/strings/truncate.go:60-62). In the two-option form the arguments are ellipsis then text, and the ellipsis must be string-convertible.","triggerScenarios":"Calling {{ truncate 50 123 .Title }} or {{ truncate 50 .SomeMap .Title }} where options[0] is not string-castable.","commonSituations":"Swapping argument order so the text lands in the ellipsis slot; passing a number or struct as the ellipsis.","solutions":["Use the correct order: truncate(length, ellipsis, text) — {{ truncate 50 \"…\" .Title }}.","If you want the default ellipsis, pass only one option: {{ truncate 50 .Title }}."],"exampleFix":"// before\n{{ truncate 50 .Title \"…\" }}\n// after\n{{ truncate 50 \"…\" .Title }}","handlingStrategy":"validation","validationCode":"{{ truncate 50 \"…\" .Title }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Two-option form is truncate(length, ellipsis, text) — ellipsis first.","Use a literal string for the ellipsis."],"tags":["template-function","strings","truncate","type-coercion","argument"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}