grafana/k6 · error

building request body: %w

Error message

building request body: %w

What it means

Raised in requestPresignedURL when buildPresignedRequestBody fails to construct the JSON payload describing the file to upload (service, operation, file name joined from basePath and path). The only realistic failure inside that helper is json.Marshal of the request struct, so this fires on serialization of an invalid value — effectively an internal invariant break, since the struct fields are plain strings.

Source

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

	defer resp.Body.Close() //nolint:errcheck

	if _, err := io.Copy(io.Discard, resp.Body); err != nil {
		return fmt.Errorf("draining upload response body: %w", err)
	}

	if err := checkStatusCode(resp); err != nil {
		return fmt.Errorf("uploading: %w", err)
	}

	return nil
}

// requestPresignedURL will request a new presigned URL from the remote server
// and returns a [PresignedURLResponse] that contains the presigned URL details.
func (r *RemoteFilePersister) requestPresignedURL(ctx context.Context, path string) (PresignedURLResponse, error) {
	b, err := buildPresignedRequestBody(r.basePath, path)
	if err != nil {
		return PresignedURLResponse{}, fmt.Errorf("building request body: %w", err)
	}

	req, err := http.NewRequestWithContext(
		ctx,
		http.MethodPost,
		r.presignedURLRequestURL,
		bytes.NewReader(b),
	)
	if err != nil {
		return PresignedURLResponse{}, fmt.Errorf("creating request: %w", err)
	}

	for k, v := range r.headers {
		req.Header.Add(k, v)
	}

	resp, err := r.httpClient.Do(req) //nolint:gosec
	if err != nil {

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Treat as an internal error: report a k6 bug with the artifact path that triggered it
  2. Update k6 to a newer version in case the payload builder was fixed
  3. Verify the basePath/path configuration values are sane strings
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/js/modules/k6/browser/storage/file_persister.go:128 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/19b550f3191a2666. Report an issue: GitHub.