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 "" -}}
$u: {{ $u }}
$u.Scheme: {{ $u.Scheme }}
$u.Host: {{ $u.Host }}

Something like this syntax? (from:

u, err := url.Parse("")
if err != nil {

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

{{- $u, $err := urls.Parse "" -}}
{{- ($u, $err) := urls.Parse "" -}}

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

if err != nil {

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

Any one has another idea?


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.