{"record":{"id":"acb8d60315de1063","repo":"ory/kratos","slug":"could-not-create-request-w","errorCode":null,"errorMessage":"could not create request: %w","messagePattern":"could not create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"schema/handler.go","lineNumber":246,"sourceCode":"func (h *Handler) ReadSchema(ctx context.Context, uri *url.URL) (data []byte, err error) {\n\tctx, span := h.r.Tracer(ctx).Tracer().Start(ctx, \"schema.Handler.ReadSchema\")\n\tdefer otelx.End(span, &err)\n\n\tswitch uri.Scheme {\n\tcase \"file\":\n\t\tdata, err = os.ReadFile(uri.Host + uri.Path) //nolint:gosec\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithStack(fmt.Errorf(\"could not read schema file: %w\", err))\n\t\t}\n\tcase \"base64\":\n\t\tdata, err = base64.StdEncoding.DecodeString(strings.TrimPrefix(uri.String(), \"base64://\"))\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithStack(fmt.Errorf(\"could not decode schema file: %w\", err))\n\t\t}\n\tdefault:\n\t\treq, err := retryablehttp.NewRequestWithContext(ctx, http.MethodGet, uri.String(), nil)\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithStack(fmt.Errorf(\"could not create request: %w\", err))\n\t\t}\n\t\tresp, err := h.r.HTTPClient(ctx).Do(req)\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithStack(herodot.ErrUpstreamError().WithReason(\"could not fetch schema\").WithError(err.Error()).WithDetail(\"uri\", uri))\n\t\t}\n\t\tdefer func() { _ = resp.Body.Close() }()\n\t\tif resp.StatusCode != http.StatusOK {\n\t\t\tif resp.StatusCode == http.StatusNotFound {\n\t\t\t\treturn nil, herodot.ErrNotFound().WithDetail(\"url\", uri)\n\t\t\t}\n\t\t\treturn nil, errors.WithStack(herodot.ErrUpstreamError().WithError(\"upstream error\").WithDetail(\"status_code\", resp.StatusCode).WithDetail(\"uri\", uri))\n\t\t}\n\t\tdata, err = io.ReadAll(io.LimitReader(resp.Body, maxSchemaSize))\n\t\tif err != nil {\n\t\t\treturn nil, errors.WithStack(herodot.ErrUpstreamError().WithReason(\"could not read schema response\").WithError(err.Error()).WithDetail(\"uri\", uri))\n\t\t}\n\t}\n\treturn data, nil","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/ory/kratos/blob/b86338da04a040247a07f46100a86dcfb3875909/schema/handler.go#L228-L264","documentation":"For file and base64 schemes ReadSchema falls through to fetching the schema over HTTP via retryablehttp. If the HTTP request itself cannot be constructed (malformed URL parsed by NewRequestWithContext), it returns \"could not create request\". This precedes any network I/O, so it indicates an invalid URI string rather than a server problem.","triggerScenarios":"Identity schema URI with an unsupported/invalid scheme or malformed URL — e.g. \"ftp://host/s.json\", \"http://[bad-ipv6\", spaces or control characters in the URL — that retryablehttp.NewRequestWithContext rejects.","commonSituations":"Unquoted config value where shell/interpolation characters corrupt the URL; typos in the scheme (htp://); env var templating producing an empty or malformed URI; copied URL containing trailing whitespace or hidden characters.","solutions":["Validate the schema URL parses (url.Parse) and uses http or https","Quote the URI in YAML/config and check for stray spaces or newline characters","Fix the scheme spelling (http:// or https://)","Verify env substitution yields the full intended URL, not an empty string"],"exampleFix":"// before\nidentity_schemas:\n  default: htp://localhost:4455/schemas/default.json\n// after\nidentity_schemas:\n  default: http://localhost:4455/schemas/default.json","handlingStrategy":"validation","validationCode":"// Go: preflight an http(s) schema URI\nfunc schemaURIFetchable(raw string) error {\n\tu, err := url.Parse(raw)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"schema URI does not parse: %w\", err)\n\t}\n\tif u.Scheme != \"http\" && u.Scheme != \"https\" {\n\t\treturn fmt.Errorf(\"unsupported scheme %q; use http(s)\", u.Scheme)\n\t}\n\treq, err := http.NewRequest(http.MethodGet, u.String(), nil)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"invalid schema request URL: %w\", err)\n\t}\n\t_ = req\n\treturn nil\n}","typeGuard":"func isParseableURL(raw string) bool {\n\t_, err := url.Parse(raw)\n\treturn err == nil\n}","tryCatchPattern":"schema, err := h.ReadSchema(ctx, uri)\nif err != nil {\n\tif strings.Contains(err.Error(), \"could not create request\") {\n\t\treturn fmt.Errorf(\"malformed schema URL %q — check scheme and characters\", uri)\n\t}\n\treturn err\n}","preventionTips":["Quote schema URLs in YAML to prevent shell/interpolation corruption","url.Parse the URI in a startup preflight","Verify env substitution resolves to a complete URL","Watch for hidden whitespace/newlines when pasting URLs from docs"],"tags":["http","url","schema","configuration"],"backgroundTag":"invalid-url","analyzedSha":"b86338da04a040247a07f46100a86dcfb3875909","analyzedAt":"2026-09-07T15:58:15.934Z","contentChangedAt":"2026-09-07T15:58:15.934Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}