{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/resources/resource_factories/create/remote.go#L234-L270","documentation":"Wrapped error from `Client.FromRemote` (remote.go:247-253) when `options.NewRequest(uri)` fails. `NewRequest` (remote.go:431-446) calls `http.NewRequest` with the method, URL, and body reader; failure means the method is invalid, the URL is incompatible with `http.NewRequest` even though `url.Parse` accepted it, or the body reader setup errored.","triggerScenarios":"Most commonly an invalid HTTP method string (e.g. `method = \"FETCH\"`, empty, or containing spaces). Also reachable if `http.NewRequest` rejects the URL for transport-level reasons (e.g. control characters in the path that `url.Parse` tolerated). Body reader errors are less common since `BodyReader()` is bytes-backed.","commonSituations":"Typo in method field; method coming from frontmatter with whitespace/newline; using a non-standard method the stdlib rejects; template interpolating an empty method string from a default.","solutions":["Use a standard HTTP method: `GET`, `POST`, `PUT`, `PATCH`, `DELETE`, `HEAD`, `OPTIONS` (uppercase).","If a custom method is required, confirm Go's `http.NewRequest` accepts it (it permits arbitrary tokens, but rejects spaces/control chars).","Trim/upper-case the method string before passing: `(upper (trim $method))`."],"exampleFix":"// template -- before\n{{ $r := resources.GetRemote $url (dict \"method\" \" fetch \") }}\n\n// after\n{{ $r := resources.GetRemote $url (dict \"method\" \"GET\") }}","handlingStrategy":"validation","validationCode":"import (\n\t\"fmt\"\n\t\"strings\"\n)\nvar allowedMethods = map[string]bool{\"GET\":true,\"POST\":true,\"PUT\":true,\"PATCH\":true,\"DELETE\":true,\"HEAD\":true,\"OPTIONS\":true}\nfunc validateMethod(m string) error {\n\tm = strings.ToUpper(strings.TrimSpace(m))\n\tif !allowedMethods[m] {\n\t\treturn fmt.Errorf(\"unsupported method %q\", m)\n\t}\n\treturn nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use standard uppercase HTTP methods.","Trim and upper-case method strings before passing.","Avoid interpolating user input directly into method fields."],"tags":["resources","remote","http","method","validation"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}