grafana/k6 · warning
unexpected value %v of type %T
Error message
unexpected value %v of type %T
What it means
count() expects the evaluation to return a JS number (deserialized as float64). Any other type — string, nil, object — triggers this error; the injected count script broke its contract or the context died.
Source
Thrown at internal/js/modules/k6/browser/common/element_handle.go:767
eopts := evalOptions{
forceCallable: true,
returnByValue: true,
}
result, err := h.evalWithScript(
apiCtx,
eopts, fn, parsedSelector,
)
if err != nil {
return 0, err
}
switch r := result.(type) {
case float64:
if r < float64(math.MinInt32) || r > float64(math.MaxInt32) {
return 0, fmt.Errorf("value %v out of range for int32 type", r)
}
return int(r), nil
default:
return 0, fmt.Errorf("unexpected value %v of type %T", r, r)
}
}
// findFrameNavigationIndex finds the index of the first internal:control=enter-frame directive
func (h *ElementHandle) findFrameNavigationIndex(selector *Selector) int {
for i, part := range selector.Parts {
if part.Name == "internal:control" && part.Body == "enter-frame" {
return i
}
}
return -1
}
// splitSelectorAtFrame splits a selector at the frame navigation boundary
func (h *ElementHandle) splitSelectorAtFrame(selector *Selector, frameIndex int) (*Selector, *Selector) {
beforeFrame := &Selector{
Selector: selector.Selector, // Keep original for reference
Parts: selector.Parts[:frameIndex],View on GitHub (pinned to 93accf6570)
Solutions
- Retry after the page settles
- Upgrade to a matching k6 build
- Report a minimal reproduction if it persists
Defensive patterns
Strategy: try-catch
Try / catch
try {
const n = await handle.count(sel);
} catch (e) {
if (String(e).includes('unexpected value')) {
await handle.count(sel); // one retry with settled context
} else { throw e; }
} Prevention
- Avoid counting during navigation
- Upgrade k6 on recurrence
When it happens
Trigger: handle.count(selector) when the eval returns undefined (execution context destroyed) or a non-numeric value from a mismatched injected script.
Common situations: Navigation racing the count; custom builds with stale injected script; rare on stock releases.
Related errors
- value %v out of range for int32 type
- unexpected type %T
- checking element is in viewport: unexpected type %T
- converting result (%v of type %t) to border: %w
- waiting for states %v of element %q
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/92f542c827d6728b.
Report an issue: GitHub.