gohugoio/hugo · error
must provide an URL and optionally an options map
Error message
must provide an URL and optionally an options map
What it means
`resources.GetRemote` accepts exactly one required argument (the URL string) and one optional options map; any other argument count fails validation. Because GetRemote reports failures through the resource's `.Err` rather than halting the build, this error arrives wrapped in a resource error you must check.
Source
Thrown at tpl/resources/resources.go:113
r, err := ns.createClient.Get(filenamestr)
if err != nil {
panic(err)
}
return r
}
// GetRemote gets the URL (via HTTP(s)) in the first argument in args and creates Resource object that can be used for
// further transformations.
//
// A second argument may be provided with an option map.
//
// Note: This method does not return any error as a second return value,
// for any error situations the error can be checked in .Err.
func (ns *Namespace) GetRemote(args ...any) (resource.Resource, error) {
get := func(args ...any) (resource.Resource, error) {
if len(args) < 1 || len(args) > 2 {
return nil, errors.New("must provide an URL and optionally an options map")
}
urlstr, err := cast.ToStringE(args[0])
if err != nil {
return nil, err
}
var options map[string]any
if len(args) > 1 {
options, err = hmaps.ToStringMapE(args[1])
if err != nil {
return nil, err
}
}
return ns.createClient.FromRemote(urlstr, options)
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Call with the URL and, optionally, one options dict: `resources.GetRemote $url (dict "headers" (dict "Authorization" $t))`.
- Combine method/body/headers into that single options map rather than separate arguments.
- Always check `.Err` on the returned resource, since GetRemote surfaces failures there.
Example fix
<!-- before -->
{{ $r := resources.GetRemote $url $headers "GET" }}
<!-- after -->
{{ $r := resources.GetRemote $url (dict "headers" $headers "method" "GET") }} Defensive patterns
Strategy: validation
Validate before calling
{{ $url := "https://example.org/data.json" }}{{ with resources.GetRemote $url (dict "headers" (dict)) }}...{{ end }} Type guard
{{ $ok := and (eq (printf "%T" $url) "string") (or (not $opts) (reflect.IsMap $opts)) }} Try / catch
{{ with try (resources.GetRemote $url $opts) }}{{ with .Err }}{{ warnf "GetRemote failed: %s" . }}{{ end }}{{ end }} Prevention
- Call resources.GetRemote with a string URL and at most one options map
- Build options with dict, not a slice or scalar
- Don't pass extra positional arguments — bundle everything into the options map
When it happens
Trigger: Calling `{{ resources.GetRemote }}` with zero arguments or with three or more, e.g. passing headers and method as separate arguments instead of inside one options dict: `resources.GetRemote $url $headers $method`.
Common situations: Migrating from getJSON/getCSV call styles that took multiple URL parts; splitting request options into separate template arguments instead of a single `dict`; templating errors where a pipeline unexpectedly yields extra values.
Related errors
- must provide targetPath, the template data context and a Res
- must provide a Resource object
- must not provide more arguments than Resource and hash algor
- failed to copy resources to vendor dir: %w
- need at least 2 arguments to append
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/8186449286300458.json.
Report an issue: GitHub ↗.