grafana/k6 · error

creating new request: %w

Error message

creating new request: %w

What it means

Raised in newFileUploadRequest when http.NewRequestWithContext fails to build the upload request from the presigned response — method '%s' from psu.Method, URL from psu.PresignedURL, body the assembled multipart form. It fires when the service-supplied presigned URL is not parseable or the method is invalid (net/http validates both), or the context is already canceled. The inputs at fault come from the remote presigned-URL response.

Source

Thrown at internal/js/modules/k6/browser/storage/file_persister.go:239

	ff, err := fw.CreateFormFile("file", psu.Name)
	if err != nil {
		return nil, fmt.Errorf("creating multipart form file: %w", err)
	}
	if _, err := io.Copy(ff, data); err != nil {
		return nil, fmt.Errorf("copying file data to multipart form: %w", err)
	}
	if err := fw.Close(); err != nil {
		return nil, fmt.Errorf("closing multipart form writer: %w", err)
	}

	req, err := http.NewRequestWithContext(
		ctx,
		psu.Method,
		psu.PresignedURL,
		&form,
	)
	if err != nil {
		return nil, fmt.Errorf("creating new request: %w", err)
	}
	req.Header.Set("Content-Type", fw.FormDataContentType())

	return req, nil
}

func checkStatusCode(resp *http.Response) error {
	if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
		return fmt.Errorf("server returned %d (%s)", resp.StatusCode, strings.ToLower(http.StatusText(resp.StatusCode)))
	}

	return nil
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Retry the persist for a fresh presigned URL
  2. Report to k6 Cloud support if the returned presigned URL or method is consistently invalid
  3. Verify the execution context is not canceled prematurely
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:239 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/1a6dad69c1eb8cfd. Report an issue: GitHub.