{"record":{"id":"8fc52a32a94a89d7","repo":"gohugoio/hugo","slug":"error-in-parse-w","errorCode":null,"errorMessage":"error in Parse: %w","messagePattern":"error in Parse: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"tpl/urls/urls.go","lineNumber":56,"sourceCode":"\tmultihost bool\n}\n\n// AbsURL takes the string s and converts it to an absolute URL.\nfunc (ns *Namespace) AbsURL(s any) (string, error) {\n\tss, err := cast.ToStringE(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn ns.deps.PathSpec.AbsURL(ss, false), nil\n}\n\n// Parse parses rawurl into a URL structure. The rawurl may be relative or\n// absolute.\nfunc (ns *Namespace) Parse(rawurl any) (*url.URL, error) {\n\ts, err := cast.ToStringE(rawurl)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in Parse: %w\", err)\n\t}\n\n\treturn url.Parse(s)\n}\n\n// RelURL takes the string s and prepends the relative path according to a\n// page's position in the project directory structure.\nfunc (ns *Namespace) RelURL(s any) (string, error) {\n\tss, err := cast.ToStringE(s)\n\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn ns.deps.PathSpec.RelURL(ss, false), nil\n}\n\n// URLize returns the strings s formatted as an URL.\nfunc (ns *Namespace) URLize(s any) (string, error) {","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/tpl/urls/urls.go#L38-L74","documentation":"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.","triggerScenarios":"Calling {{ urls.Parse $value }} where $value is a number, slice, struct, or other non-stringifiable type passed from front matter, params, or scratch.","commonSituations":"Piping a .Param that holds an integer or a resource object into urls.Parse; passing a []string from a template loop.","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"],"exampleFix":"// before\n{{ urls.Parse $count }}\n// after\n{{ urls.Parse (string $count) }}","handlingStrategy":"validation","validationCode":"// Ensure the argument is string-convertible.\nif _, err := cast.ToStringE(rawurl); err != nil {\n    return nil, fmt.Errorf(\"urls.Parse needs a string, got %T\", rawurl)\n}\n// In templates: {{ urls.Parse (string $value) }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Stringify values before urls.Parse","Prefer urls.URLize for plain normalization which also stringifies","Type-check front matter params before piping into Parse"],"tags":["template","urls","parse","type-conversion"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}