grafana/k6 · error

handleSummary() should return a map with string keys

Error message

handleSummary() should return a map with string keys

What it means

A user-defined handleSummary callback ran successfully but its return value, after export to Go, is not a map[string]any. k6 expects a plain object whose keys are output destinations (file paths, 'stdout', 'stderr', or https:// URLs) and whose values are summary text or data. Returning an array, a string, a class instance, or an array of pairs fails this type assertion.

Source

Thrown at internal/js/summary.go:216

	}

	return map[string]any{
		"name":   group.Name,
		"path":   group.Path,
		"id":     group.ID,
		"groups": subGroups,
		"checks": checks,
	}
}

func getSummaryResult(rawResult sobek.Value) (map[string]io.Reader, error) {
	if common.IsNullish(rawResult) {
		return nil, nil //nolint:nilnil // this is actually valid result in this case
	}

	rawResultMap, ok := rawResult.Export().(map[string]any)
	if !ok {
		return nil, fmt.Errorf("handleSummary() should return a map with string keys")
	}

	results := make(map[string]io.Reader, len(rawResultMap))
	for path, val := range rawResultMap {
		readerVal, err := common.GetReader(val)
		if err != nil {
			return nil, fmt.Errorf("error handling summary object %s: %w", path, err)
		}
		results[path] = readerVal
	}

	return results, nil
}

View on GitHub (pinned to 01ffac6f24)

Solutions

  1. Return a plain object literal, e.g. { 'stdout': textSummary(data), 'file.json': JSON.stringify(data) }
  2. Do not return arrays, Maps, or constructor instances; use plain object literals so they export as map[string]any
  3. Returning undefined/null is also accepted and produces no custom output
Defensive patterns

Strategy: type-guard

When it happens

Trigger: Thrown at internal/js/summary.go:216 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/17b6b730204ffdf2. Report an issue: GitHub.