gohugoio/hugo · error

must provide a Resource object

Error message

must provide a Resource object

What it means

`resources.Fingerprint` requires at least one argument — the Resource to hash (an optional hash algorithm string like "sha256" may precede it). Calling it with no arguments fails this length check before any processing. A separate error covers more than two arguments.

Source

Thrown at tpl/resources/resources.go:263

	targetPath, err := cast.ToStringE(args[0])
	if err != nil {
		return nil, err
	}
	data := args[1]

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

	return ns.templatesClient.ExecuteAsTemplate(ctx, r, targetPath, data)
}

// Fingerprint transforms the given Resource with a MD5 hash of the content in
// the RelPermalink and Permalink.
func (ns *Namespace) Fingerprint(args ...any) (resource.Resource, error) {
	if len(args) < 1 {
		return nil, errors.New("must provide a Resource object")
	}

	if len(args) > 2 {
		return nil, errors.New("must not provide more arguments than Resource and hash algorithm")
	}

	var algo string
	resIdx := 0

	if len(args) == 2 {
		resIdx = 1
		var err error
		algo, err = cast.ToStringE(args[0])
		if err != nil {
			return nil, err
		}
	}

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Pipe the resource in: `{{ $css := $css | fingerprint }}` or `{{ $css | fingerprint "sha256" }}` — the pipe supplies the Resource as the last argument.
  2. If the resource may be nil (missing asset), guard with `with` before fingerprinting.
  3. When specifying an algorithm, put it first and the resource last: `fingerprint "sha512" $r` (or via pipe).

Example fix

<!-- before -->
{{ $secure := fingerprint }}
<!-- after -->
{{ $secure := $js | fingerprint "sha256" }}
Defensive patterns

Strategy: type-guard

Validate before calling

{{ with resources.Get "style.scss" }}{{ $css := . | toCSS }}{{ end }}

Type guard

{{/* `with` narrows away nil */}}{{ with $maybeResource }}{{ resources.Minify . }}{{ end }}

Try / catch

{{ with try (resources.Minify $r) }}{{ with .Err }}{{ warnf "minify failed: %s" . }}{{ end }}{{ end }}

Prevention

When it happens

Trigger: `{{ resources.Fingerprint }}` with nothing piped or passed; a pipeline where the upstream step returned nothing so no resource reaches Fingerprint (e.g. `resources.Get` used in a broken chain); calling `fingerprint` as a bare function instead of piping the resource into it.

Common situations: Refactoring an asset pipeline and dropping the piped resource; conditional blocks where the resource variable is empty; copying docs examples without the leading `$resource |`.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/259a8b2f316a6fdc.json. Report an issue: GitHub ↗.