grafana/k6 · error

unexpected error while generating the summary: %w

Error message

unexpected error while generating the summary: %w

What it means

The handleSummary wrapper function was invoked but its execution returned an error. Unlike the wrapper-compilation error, this fires while the summary code actually runs, so the cause is usually the user-supplied handleSummary callback throwing (e.g. accessing a missing data field) or an error inside the bundled summary rendering logic.

Source

Thrown at internal/js/runner.go:424

	if err != nil {
		return nil, fmt.Errorf("unexpected error while getting the summary wrapper: %w", err)
	}
	handleSummaryWrapper, ok := sobek.AssertFunction(handleSummaryWrapperRaw)
	if !ok {
		return nil, fmt.Errorf("unexpected error did not get a callable summary wrapper")
	}

	wrapperArgs := prepareHandleWrapperArgs(
		vu, noColor, enableColors, newMachineReadableSummary, callbackResult, handleSummaryData, summaryData,
	)
	rawResult, _, _, err := vu.runFn(summaryCtx, false, handleSummaryWrapper, nil, wrapperArgs...)

	if deadlineError := r.checkDeadline(summaryCtx, consts.HandleSummaryFn, rawResult, err); deadlineError != nil {
		return nil, deadlineError
	}

	if err != nil {
		return nil, fmt.Errorf("unexpected error while generating the summary: %w", err)
	}

	return getSummaryResult(rawResult)
}

func prepareHandleSummaryCall(
	r *Runner,
	rt *sobek.Runtime,
	legacy *lib.LegacySummary,
	s *summary.Summary,
	meta summary.Meta,
) (bool, bool, bool, string, sobek.Value, sobek.Value, error) {
	var (
		noColor                   bool
		enableColors              bool
		newMachineReadableSummary bool
		summaryCode               string
		summaryData               sobek.Value

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Wrap the body of handleSummary in try/catch and log the caught error to stderr to isolate the failing line
  2. Verify the data argument structure (data.metrics, data.groups, data.checks, data.options) before accessing nested fields
  3. Return well-formed entries: a map of filename/URL path to string or object payload
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at internal/js/runner.go:424 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/e886bda0c1a08345. Report an issue: GitHub.