{"record":{"id":"9ac6a58e5f4a8183","repo":"grafana/k6","slug":"failed-to-create-request-w","errorCode":null,"errorMessage":"failed to create request: %w","messagePattern":"failed to create request: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/secretsource/url/url.go","lineNumber":178,"sourceCode":"func (us *urlSecrets) Get(key string) (string, error) {\n\tctx := context.Background()\n\n\tif err := us.limiter.Wait(ctx); err != nil {\n\t\treturn \"\", fmt.Errorf(\"rate limiter error: %w\", err)\n\t}\n\n\tvar secret string\n\t// MaxRetries is the number of retries, so total attempts = retries + 1\n\tmaxAttempts := int(us.config.MaxRetries.Int64) + 1\n\tbackoff := time.Duration(us.config.RetryBackoff.Duration)\n\n\terr := retry(ctx, maxAttempts, backoff, us.logger, func() (error, bool) {\n\t\t// Replace {key} placeholder in URL template\n\t\turl := strings.ReplaceAll(us.config.URLTemplate, \"{key}\", key)\n\n\t\treq, err := http.NewRequestWithContext(ctx, us.config.Method.String, url, nil)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to create request: %w\", err), true\n\t\t}\n\n\t\t// Add headers\n\t\tfor k, v := range us.config.Headers {\n\t\t\treq.Header.Set(k, v)\n\t\t}\n\n\t\tresponse, err := us.httpClient.Do(req) //nolint:gosec\n\t\tif err != nil {\n\t\t\t// Network errors are retryable\n\t\t\treturn fmt.Errorf(\"failed to get secret: %w\", err), true\n\t\t}\n\t\tdefer func() { _ = response.Body.Close() }()\n\n\t\tif response.StatusCode != http.StatusOK {\n\t\t\tstatusErr := fmt.Errorf(\"status code %d: %w\", response.StatusCode, errFailedToGetSecret)\n\n\t\t\t// Retry on server errors (5xx) and rate limiting (429)","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/grafana/k6/blob/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/secretsource/url/url.go#L160-L196","documentation":"Building the HTTP request for a secret fetch failed at http.NewRequestWithContext — almost always an invalid URL after substituting the key into urlTemplate, or an invalid HTTP method configured for the source.","triggerScenarios":"Thrown at internal/secretsource/url/url.go:178 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Fix urlTemplate so it forms a valid absolute URL for any key","Verify the configured HTTP method (GET/POST) is valid"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}