HUGO

urls.Parse - wrong URL detection?

Is there a way to know if there is an error during parsing? I want to trigger a warnf/errorf in my log in case some URL is not properly working.

This works, but no error detection

{{- $u := urls.Parse "bing.com/search?q=dotnet" -}}
$u: {{ $u }}
$u.Scheme: {{ $u.Scheme }}
$u.Host: {{ $u.Host }}

Something like this syntax? (from: https://godoc.org/net/url#URL)

u, err := url.Parse("http://bing.com/search?q=dotnet")
if err != nil {
    log.Fatal(err)
}

I tried, but the function only returns one argument, so these are not working:

{{- $u, $err := urls.Parse "bing.com/search?q=dotnet" -}}
{{- ($u, $err) := urls.Parse "bing.com/search?q=dotnet" -}}

In Hugo source code, i see it triggers panic(), but I am not sure if I can piggyback on this.

if err != nil {
	panic(err)
}

So far, I am checking if $u.Scheme and $u.Host are not defined.

Any one has another idea?

Anyone?

You cannot, and I agree that that is unfortunate in this case.

I will stay with my $u.Scheme / $u.Hos check then. It fits my use case.