gohugoio/hugo · error

too few arguments

Error message

too few arguments

What it means

Thrown by strings.Substr when called with no numeric arguments after the string. Substr requires at least a start index; calling it with only the string (zero extra args) is a usage error. (This is distinct from SliceString which permits zero indices.)

Solutions

  1. Always provide at least a start index: {{ strings.Substr $s $start }}.
  2. Use strings.SliceString $s (no indices) if you want the whole string.
  3. Double-check the call after refactors that move arguments.

Example fix

// before
{{ strings.Substr $s }}
// after
{{ strings.Substr $s 0 }}
Defensive patterns

Strategy: validation

Validate before calling

{{ strings.Substr $s 0 }}

Prevention

When it happens

Trigger: Calling {{ strings.Substr $s }} with no start index, or piping a string into Substr without an index: {{ $s | strings.Substr }}.

Common situations: Confusing Substr with a no-arg function; refactoring that dropped the start argument; piping where the index was expected positionally.

Related errors


AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09). Data as JSON: /api/errors/4f79ab9e3a8f18e9. Report an issue: GitHub.

Appendix: source

Thrown at tpl/strings/strings.go:396

// To extract characters from the end of the string, use a negative start number.
//
// In addition, borrowing from the extended behavior described at http://php.net/substr,
// if length is given and is negative, then that many characters will be omitted from
// the end of string.
func (ns *Namespace) Substr(a any, nums ...any) (string, error) {
	s, err := cast.ToStringE(a)
	if err != nil {
		return "", err
	}

	asRunes := []rune(s)
	rlen := len(asRunes)

	var start, length int

	switch len(nums) {
	case 0:
		return "", errors.New("too few arguments")
	case 1:
		if start, err = cast.ToIntE(nums[0]); err != nil {
			return "", errors.New("start argument must be an integer")
		}
		length = rlen
	case 2:
		if start, err = cast.ToIntE(nums[0]); err != nil {
			return "", errors.New("start argument must be an integer")
		}
		if length, err = cast.ToIntE(nums[1]); err != nil {
			return "", errors.New("length argument must be an integer")
		}
	default:
		return "", errors.New("too many arguments")
	}

	if rlen == 0 {
		return "", nil

View on GitHub (pinned to 52c9bd7908)