grafana/k6 · error
must be a number
Error message
must be a number
What it means
exportInt (used by File.seek) requires the value's Go export type to be exactly int64 -- i.e. an integral JavaScript number. Strings like "10" (explicitly called out in the source comment), fractional numbers such as 10.5, and BigInts all fail this check and surface as "seek() failed; reason: the offset/whence argument must be a number".
Source
Thrown at internal/js/modules/k6/experimental/fs/module.go:352
uint8ArrayConstructor := rt.Get("Uint8Array")
if isUint8Array := o.Get("constructor").SameAs(uint8ArrayConstructor); !isUint8Array {
return false
}
return true
}
func exportInt(v sobek.Value) (int64, error) {
if common.IsNullish(v) {
return 0, errors.New("cannot be null or undefined")
}
// We initially tried using `ExportTo` with a int64 value argument, however
// this led to a string passed as argument not being an error.
// Thus, we explicitly check that the value is a number, by comparing
// its export type to the type of an int64.
if v.ExportType().Kind() != reflect.Int64 {
return 0, errors.New("must be a number")
}
return v.ToInteger(), nil
}
View on GitHub (pinned to 93accf6570)
Solutions
- Coerce before calling: file.seek(Number(offset), SeekMode.Start)
- Round fractional values: file.seek(Math.round(pos), whence)
- Use SeekMode.Start/Current/End constants instead of strings for whence
Example fix
// before
await file.seek(offsetStr, 'Start');
// after
import { SeekMode } from 'k6/experimental/fs';
await file.seek(Number(offsetStr), SeekMode.Start); Defensive patterns
Strategy: validation
Validate before calling
function isSeekArg(v) {
return typeof v === 'number' && Number.isInteger(v);
}
if (!isSeekArg(offset) || !isSeekArg(whence)) throw new TypeError('seek arguments must be integers');
await file.seek(offset, whence); Type guard
/** @param {unknown} v @returns {v is number} */
const isInt = (v) => typeof v === 'number' && Number.isInteger(v); Prevention
- Coerce external data with Number() and Math.round() before seeking
- Use the SeekMode enum, never strings, for whence
- Reject fractional offsets early with Number.isInteger to get your own clearer message
When it happens
Trigger: file.seek('1024', 0) with a string offset read from CSV/stdin/config; file.seek(10.5, 0) with a fractional offset; passing whence as a string like 'Start' instead of the numeric SeekMode enum.
Common situations: Offsets parsed from external data files that stay strings; computed offsets from averages/percentages that are non-integral; using string mode names from other APIs.
Related errors
- cannot be null or undefined
- stack URL is required to validate token
- 104
- invalid tag, empty name
- invalid tag, empty value
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/13d5a4c690a4ce1f.
Report an issue: GitHub.