{"id":"3831d956a2d56438","repo":"gohugoio/hugo","slug":"failed-to-create-request-for-resource-s-w","errorCode":null,"errorMessage":"failed to create request for resource %s: %w","messagePattern":"failed to create request for resource (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"resources/resource_factories/create/remote.go","lineNumber":252,"sourceCode":"\n\t\tif err := c.validateFromRemoteArgs(uri, options); err != nil {\n\t\t\treturn nil, err\n\t\t}\n\n\t\tgetRes := func() (*http.Response, context.CancelFunc, error) {\n\t\t\tctx := context.Background()\n\t\t\tvar cancel context.CancelFunc\n\t\t\tif perRequestTimeout > 0 {\n\t\t\t\tctx, cancel = context.WithTimeout(ctx, perRequestTimeout)\n\t\t\t}\n\t\t\tctx = c.resourceIDDispatcher.Set(ctx, filecacheKey)\n\n\t\t\treq, err := options.NewRequest(uri)\n\t\t\tif err != nil {\n\t\t\t\tif cancel != nil {\n\t\t\t\t\tcancel()\n\t\t\t\t}\n\t\t\t\treturn nil, nil, fmt.Errorf(\"failed to create request for resource %s: %w\", uri, err)\n\t\t\t}\n\n\t\t\treq = req.WithContext(ctx)\n\n\t\t\tresp, err := c.httpClient.Do(req)\n\t\t\tif err != nil {\n\t\t\t\tif cancel != nil {\n\t\t\t\t\tcancel()\n\t\t\t\t}\n\t\t\t\treturn nil, nil, err\n\t\t\t}\n\t\t\treturn resp, cancel, nil\n\t\t}\n\n\t\tres, cancel, err := getRes()\n\t\tif cancel != nil {\n\t\t\tdefer cancel()\n\t\t}","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/resources/resource_factories/create/remote.go#L234-L270","documentation":"After decoding options, Hugo builds the `*http.Request` via `options.NewRequest(uri)`. This fails when `http.NewRequest` rejects the inputs — most commonly an invalid HTTP method string or a URL/body combination Go's http package won't accept. It fires before the request is sent, so it's a construction problem, not a network one.","triggerScenarios":"Calling `resources.GetRemote` with a `method` option containing an invalid token (spaces, lowercase is normalized but e.g. `\"GET \"` with whitespace or a non-token character fails), or a URI form that parsed leniently in step one but is rejected by `http.NewRequest` (e.g. missing scheme in some forms), or a body option that can't form a request.","commonSituations":"Method values from data files with stray whitespace or quotes, using a relative or scheme-less URL (`//example.com/x` or `example.com/x`), or unusual custom methods with illegal characters.","solutions":["Ensure the URL is absolute with an explicit scheme: `https://example.com/...`.","Sanitize the `method` option: valid HTTP token, no whitespace, e.g. `dict \"method\" \"post\"`.","Read the wrapped Go error text — it states exactly what http.NewRequest rejected — and correct that input."],"exampleFix":"{{/* before */}}\n{{ $r := resources.GetRemote \"example.com/api\" (dict \"method\" \"POST \") }}\n{{/* after */}}\n{{ $r := resources.GetRemote \"https://example.com/api\" (dict \"method\" \"post\") }}","handlingStrategy":"validation","validationCode":"{{/* method must be a valid HTTP token; URL must be well-formed */}}\n{{ $method := upper (default \"get\" .Params.method) }}\n{{ if not (in (slice \"GET\" \"POST\" \"HEAD\") $method) }}\n  {{ errorf \"unsupported method %q for %s\" $method $url }}\n{{ end }}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep the method option a plain HTTP verb — embedded spaces or control characters make http.NewRequest fail","Validate the URL (see index 323) — request construction fails on malformed URLs too","Don't interpolate untrusted content directly into method or header names"],"tags":["hugo","get-remote","http-request","templates"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}