grafana/k6 · error

decoding response body: %w

Error message

decoding response body: %w

What it means

Raised in readPresignedURLResponse when json.Decoder.Decode fails while parsing the presigned-URL service response body into PresignedURLResponse. This fires when the remote endpoint returns a body that is not valid JSON or is truncated — e.g. an HTML error page from a proxy, a gateway timeout body, or a connection cut mid-response. Note the distinct sibling check: a valid JSON body with zero URLs produces 'missing presigned url in response body' instead.

Source

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

			},
		},
	}

	bb, err := json.Marshal(b)
	if err != nil {
		return nil, fmt.Errorf("marshaling request body: %w", err)
	}

	return bb, nil
}

func readPresignedURLResponse(resp *http.Response) (PresignedURLResponse, error) {
	var rb PresignedURLResponse

	decoder := json.NewDecoder(resp.Body)
	err := decoder.Decode(&rb)
	if err != nil {
		return PresignedURLResponse{}, fmt.Errorf("decoding response body: %w", err)
	}

	if len(rb.URLs) == 0 {
		return PresignedURLResponse{}, errors.New("missing presigned url in response body")
	}

	return rb, nil
}

// newFileUploadRequest creates a new HTTP request to upload a file as a multipart
// form to the presigned URL received from the server.
func newFileUploadRequest(
	ctx context.Context,
	resp PresignedURLResponse,
	data io.Reader,
) (*http.Request, error) {
	// we don't support multiple presigned URLs at the moment.
	psu := resp.URLs[0]

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Verify the presigned-URL endpoint configuration points to the real k6 Cloud API
  2. Check for intermediary proxies returning HTML error pages
  3. Retry the persist; transient gateway/proxy failures are common
  4. Capture the raw response body (debug logging) to identify what non-JSON content was returned
Defensive patterns

Strategy: retry

When it happens

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