gohugoio/hugo · error
error in Parse
Error message
error in Parse: %w
What it means
Thrown by urls.Parse (tpl/urls/urls.go:56) when cast.ToStringE(rawurl) fails to convert the argument to a string. The underlying cast error is wrapped with 'error in Parse'. Note that a successful string conversion can still fail later in url.Parse with a separate error.
Solutions
- Coerce the value to a string first: {{ urls.Parse (string $value) }}
- Guard with a string type check before calling Parse
- Use urls.URLize for plain string normalization which also stringifies
Example fix
// before
{{ urls.Parse $count }}
// after
{{ urls.Parse (string $count) }} Defensive patterns
Strategy: validation
Validate before calling
// Ensure the argument is string-convertible.
if _, err := cast.ToStringE(rawurl); err != nil {
return nil, fmt.Errorf("urls.Parse needs a string, got %T", rawurl)
}
// In templates: {{ urls.Parse (string $value) }} Prevention
- Stringify values before urls.Parse
- Prefer urls.URLize for plain normalization which also stringifies
- Type-check front matter params before piping into Parse
When it happens
Trigger: Calling {{ urls.Parse $value }} where $value is a number, slice, struct, or other non-stringifiable type passed from front matter, params, or scratch.
Common situations: Piping a .Param that holds an integer or a resource object into urls.Parse; passing a []string from a template loop.
Related errors
- end argument must be integer
- illegal number syntax
- integer overflow
- invalid number of arguments to ref
- invalid Page received in Ref
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/8fc52a32a94a89d7.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/urls/urls.go:56
multihost bool
}
// AbsURL takes the string s and converts it to an absolute URL.
func (ns *Namespace) AbsURL(s any) (string, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return "", err
}
return ns.deps.PathSpec.AbsURL(ss, false), nil
}
// Parse parses rawurl into a URL structure. The rawurl may be relative or
// absolute.
func (ns *Namespace) Parse(rawurl any) (*url.URL, error) {
s, err := cast.ToStringE(rawurl)
if err != nil {
return nil, fmt.Errorf("error in Parse: %w", err)
}
return url.Parse(s)
}
// RelURL takes the string s and prepends the relative path according to a
// page's position in the project directory structure.
func (ns *Namespace) RelURL(s any) (string, error) {
ss, err := cast.ToStringE(s)
if err != nil {
return "", err
}
return ns.deps.PathSpec.RelURL(ss, false), nil
}
// URLize returns the strings s formatted as an URL.
func (ns *Namespace) URLize(s any) (string, error) {View on GitHub (pinned to 52c9bd7908)