resources.GetRemote: validation of number of arguments

Another minor issue I came across:

I’m fetching local resources via resources.Get:

{{ $image := resources.Get "box.png" "invalidSecondArgument"}}

With this code, I’m getting an error::

execute of template failed at <resources>: wrong number of args for Get: want 1 got 2

However, fetching remote resources via resources.GetRemote, passing a third argument does not result in an error:

{{- with resources.GetRemote "https://httpbin.org/get"  ( dict "method" "post" ) "third_argument" }}
<a href="{{- .RelPermalink -}}">JSON</a> from httpbin
{{ end}}

Question: Does resources.GetRemote take more than two arguments? If not, hugo should validate the number of arguments given (as with resources.Get).

Practical use: see this code:

{{- with resources.GetRemote "https://httpbin.org/get" dict "method" "post" }}
{{ end}}

Due to missing parenthesis, this code does not what it is supposed to (specifying a options dict), potentially confusing users. With validation for number of arguments in place, this code would result in an error.

Meanwhile, I checked the source code and realized that GetRemote is defined as variadic function:

// 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 argument,
// for any error situations the error can be checked in .Err.
func (ns *Namespace) GetRemote(args ...any) resource.Resource {

In the function body, only args[0] and args[1] are used though.
I think there is room for improvement here.

2 Likes