gohugoio/hugo · error

invalid options type

Error message

invalid options type: %w

What it means

In the two-argument form, the first argument (treated as the options map) could not be converted to map[string]any by hmaps.ToStringMapE. The wrapped error (%w) explains the conversion failure. See helpers.go:63-66.

Solutions

  1. Pass options as a map (dict in templates) or an object convertible to map[string]any.
  2. Check the type of the options variable before calling.
  3. Omit the options argument entirely when no options are needed (use the 1-arg form).

Example fix

// before
{{ $r | css.Sass 42 }}

// after
{{ $r | css.Sass (dict "outputStyle" "compressed") }}
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the options argument is a map[string]any (or convertible) before passing.
m, err := hmaps.ToStringMapE(options)
if err != nil {
    return fmt.Errorf("options must be a map: %w", err)
}

Type guard

func isOptionsMap(v any) bool {
    switch v.(type) {
    case map[string]any, map[string]interface{}: return true
    }
    return false
}

Prevention

When it happens

Trigger: Passing an int, struct, slice, or other non-map value as the options argument, e.g. {{ $r | css.Sass 42 }}.

Common situations: Typo passing the wrong variable as options; a typed config struct that ToStringMapE cannot coerce; treating a positional arg as options when it should be the resource.

Related errors


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

Appendix: source

Thrown at tpl/internal/resourcehelpers/helpers.go:65

	if len(args) == 1 {
		r, ok := args[0].(resources.ResourceTransformer)
		if !ok {
			return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
		}
		return r, nil, nil
	}

	r, ok := args[1].(resources.ResourceTransformer)
	if !ok {
		if _, ok := args[1].(map[string]any); !ok {
			return nil, nil, fmt.Errorf("no Resource provided in transformation")
		}
		return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
	}

	m, err := hmaps.ToStringMapE(args[0])
	if err != nil {
		return nil, nil, fmt.Errorf("invalid options type: %w", err)
	}

	return r, m, nil
}

View on GitHub (pinned to 52c9bd7908)