grafana/k6 · error
cannot be null or undefined
Error message
cannot be null or undefined
What it means
File.seek(offset, whence) validates both arguments through exportInt, which rejects null or undefined values. Because whence is a required parameter, calling seek with only an offset is the most common way to hit this; the message is prefixed at the call site, e.g. "seek() failed; reason: the whence argument cannot be null or undefined".
Source
Thrown at internal/js/modules/k6/experimental/fs/module.go:344
return resolve(newOffset)
})
}()
return promise, nil
}
func isUint8Array(rt *sobek.Runtime, o *sobek.Object) bool {
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
- Always pass both arguments: file.seek(0, SeekMode.Start)
- Import SeekMode from 'k6/experimental/fs' and use its constants (Start=0, Current=1, End=2)
- Default missing whence at the call site: file.seek(off, whence ?? SeekMode.Start)
Example fix
// before
await file.seek(1024);
// after
import { SeekMode } from 'k6/experimental/fs';
await file.seek(1024, SeekMode.Start); Defensive patterns
Strategy: validation
Validate before calling
import { SeekMode } from 'k6/experimental/fs';
function seekTo(file, offset, whence = SeekMode.Start) {
if (offset === null || offset === undefined || whence === null || whence === undefined) {
throw new TypeError('seek requires a numeric offset and a SeekMode whence');
}
return file.seek(offset, whence);
} Prevention
- Treat whence as mandatory: always write file.seek(n, SeekMode.Start)
- Default conditional whence at your own call site, not by omitting the argument
- Remember SeekMode constants: Start=0, Current=1, End=2
When it happens
Trigger: file.seek(0) with the whence argument omitted (it is mandatory); file.seek(null, SeekMode.Start); passing undefined explicitly for either argument.
Common situations: Assuming Node.js-style optional position arguments; porting code that used a single-argument seek; sparse call sites where whence is conditionally passed.
Related errors
- must be a number
- accepts %d arg(s), received %d: %s
- stack URL is required to validate token
- 104
- invalid tag, empty name
AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15).
Data as JSON: /api/errors/ffd3534aec4bf048.
Report an issue: GitHub.