{"record":{"id":"0e1c496d786f15f8","repo":"gohugoio/hugo","slug":"too-many-fields-in-options-parameter-to-numfmt","errorCode":null,"errorMessage":"too many fields in options parameter to NumFmt","messagePattern":"too many fields in options parameter to NumFmt","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/lang/lang.go","lineNumber":178,"sourceCode":"\t\t\tdelim = s\n\t\t}\n\n\t\ts, err := cast.ToStringE(options[0])\n\t\tif err != nil {\n\t\t\treturn \"\", err\n\t\t}\n\n\t\trs := strings.Split(s, delim)\n\t\tswitch len(rs) {\n\t\tcase 0:\n\t\tcase 1:\n\t\t\tneg = rs[0]\n\t\tcase 2:\n\t\t\tneg, dec = rs[0], rs[1]\n\t\tcase 3:\n\t\t\tneg, dec, grp = rs[0], rs[1], rs[2]\n\t\tdefault:\n\t\t\treturn \"\", errors.New(\"too many fields in options parameter to NumFmt\")\n\t\t}\n\t}\n\n\texp := math.Pow(10.0, float64(prec))\n\tr := math.Round(n*exp) / exp\n\n\t// Logic from MIT Licensed github.com/gohugoio/locales/\n\t// Original Copyright (c) 2016 Go Playground\n\n\ts := strconv.FormatFloat(math.Abs(r), 'f', prec, 64)\n\tL := len(s) + 2 + len(s[:len(s)-1-prec])/3\n\n\tvar count int\n\tinWhole := prec == 0\n\tb := make([]byte, 0, L)\n\n\tfor i := len(s) - 1; i >= 0; i-- {\n\t\tif s[i] == '.' {","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/lang/lang.go#L160-L196","documentation":"Thrown by lang.FormatNumberCustom (NumFmt) at tpl/lang/lang.go:178 when the options string, split by the delimiter, yields more than three fields. The options string encodes at most three values: negative sign, decimal mark, and grouping separator. A fourth field has no meaning and is rejected.","triggerScenarios":"Calling {{ lang.NumFmt 2 1234.56 \"- . , \" }} where an extra space creates a fourth empty field, or passing \"- . , x\" with four real fields; using a delimiter that does not match the intended split; double spaces producing empty tokens.","commonSituations":"Trailing or doubled spaces in the options string (each space is a delimiter by default), creating empty extra fields; copying format strings from another locale library with a different field count; misunderstanding that only three fields are allowed.","solutions":["Use exactly three fields max: negative sign, decimal mark, grouping separator (default is \"- . ,\").","Remove extra/doubled spaces in the options string; trim trailing whitespace.","If you need a different delimiter, pass it as the second options arg: {{ lang.NumFmt 2 1.5 \"-|.|,\" \"|\" }}.","Omit the options arg entirely to accept the defaults."],"exampleFix":"// before\n{{ lang.NumFmt 2 1234.56 \"- . ,  \" }}\n\n// after\n{{ lang.NumFmt 2 1234.56 \"- . ,\" }}","handlingStrategy":"validation","validationCode":"// Keep options to at most three fields (neg, dec, grp) with no extra delimiters:\n{{ lang.NumFmt 2 1234.56 \"- . ,\" }}\n// Or use a custom delimiter and trim stray tokens:\n{{ lang.NumFmt 2 1234.56 \"-|.|.\" \"|\" }}","typeGuard":"// Go caller: validate the options string fields before FormatNumberCustom:\nfunc validNumFmtOptions(s, delim string) bool {\n    return len(strings.Split(s, delim)) <= 3\n}","tryCatchPattern":null,"preventionTips":["Use at most three fields: negative sign, decimal mark, grouping separator.","Avoid trailing or doubled spaces (the default delimiter is a space).","Omit the options arg to accept the default \"- . ,\"."],"tags":["hugo","template","lang","formatting","argument-validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}