{"record":{"id":"de6d2236d793dd62","repo":"gohugoio/hugo","slug":"failed-to-parse-url-for-resource-s-w","errorCode":null,"errorMessage":"failed to parse URL for resource %s: %w","messagePattern":"failed to parse URL for resource (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_factories/create/remote.go","lineNumber":198,"sourceCode":"\t\t\t\tif time.Since(lastChange) < 10*time.Second {\n\t\t\t\t\t// The user is typing, check more often.\n\t\t\t\t\treturn 0, nil\n\t\t\t\t}\n\n\t\t\t\t// Increase the interval to avoid hammering the server.\n\t\t\t\tinterval += 1 * time.Second\n\n\t\t\t\treturn interval, nil\n\t\t\t},\n\t\t})\n}\n\n// FromRemote expects one or n-parts of a URL to a resource\n// If you provide multiple parts they will be joined together to the final URL.\nfunc (c *Client) FromRemote(uri string, optionsm map[string]any) (resource.Resource, error) {\n\trURL, err := url.Parse(uri)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to parse URL for resource %s: %w\", uri, err)\n\t}\n\n\tmethod := \"GET\"\n\tif s, _, ok := hmaps.LookupEqualFold(optionsm, \"method\"); ok {\n\t\tmethod = strings.ToUpper(s.(string))\n\t}\n\tisHeadMethod := method == \"HEAD\"\n\n\toptionsm = maps.Clone(optionsm)\n\n\t// Extract timeout before computing cache keys: it only affects fetch behaviour,\n\t// not the cached content, so it must not influence the cache key.\n\tvar perRequestTimeout time.Duration\n\tif v, k, ok := hmaps.LookupEqualFold(optionsm, \"timeout\"); ok {\n\t\td, err := cast.ToDurationE(v)\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"invalid timeout for resource %s: %w\", uri, err)\n\t\t}","sourceCodeStart":180,"sourceCodeEnd":216,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource_factories/create/remote.go#L180-L216","documentation":"Wrapped error from `Client.FromRemote` (remote.go:196-198) when `url.Parse(uri)` fails. Hugo requires a syntactically valid URL before doing anything else with the remote resource request. The error from the stdlib `url.Parse` is wrapped with the offending URI for context.","triggerScenarios":"Calling `resources.GetRemote` / `FromRemote` with a malformed URL string: unescaped spaces, missing scheme (`example.com/x`), stray control characters, unbalanced brackets, or template interpolation injecting bad characters.","commonSituations":"Template builds URL via `printf` without escaping user input; missing `http://`/`https://` scheme; copy-paste from a rich-text editor inserting non-breaking spaces; query params with raw `&`/`#`; content frontmatter URL field with leading/trailing whitespace or stray quotes.","solutions":["Ensure the URL has an explicit scheme and host (`https://...`).","URL-encode dynamic path/query segments with `htmlEscape`/`urlquery` before assembling.","Trim whitespace and strip smart quotes from frontmatter-supplied URLs.","Pre-validate with a quick `url.Parse` test harness for frontmatter URLs."],"exampleFix":"// template -- before\n{{ $r := resources.GetRemote (printf \"%s/%s\" $base $slug) }}\n\n// after\n{{ $r := resources.GetRemote (printf \"%s/%s\" $base (urlquery $slug)) }}","handlingStrategy":"validation","validationCode":"import \"net/url\"\nfunc validateRemoteURL(s string) error {\n\tu, err := url.Parse(s)\n\tif err != nil { return err }\n\tif u.Scheme == \"\" || u.Host == \"\" {\n\t\treturn fmt.Errorf(\"URL %q missing scheme or host\", s)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":"// Template-side guard.\n{{ $u := urls.Parse $raw }}\n{{ if and $u.Scheme $u.Host }}{{ $r := resources.GetRemote $raw }}{{ end }}","preventionTips":["Always include `https://` (or `http://`).","URL-encode dynamic segments via `urlquery`/`htmlEscape`.","Trim whitespace from frontmatter URL fields."],"tags":["resources","remote","url","validation","network"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}