{"record":{"id":"ffd3534aec4bf048","repo":"grafana/k6","slug":"cannot-be-null-or-undefined","errorCode":null,"errorMessage":"cannot be null or undefined","messagePattern":"cannot be null or undefined","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/fs/module.go","lineNumber":344,"sourceCode":"\t\t\treturn resolve(newOffset)\n\t\t})\n\t}()\n\n\treturn promise, nil\n}\n\nfunc isUint8Array(rt *sobek.Runtime, o *sobek.Object) bool {\n\tuint8ArrayConstructor := rt.Get(\"Uint8Array\")\n\tif isUint8Array := o.Get(\"constructor\").SameAs(uint8ArrayConstructor); !isUint8Array {\n\t\treturn false\n\t}\n\n\treturn true\n}\n\nfunc exportInt(v sobek.Value) (int64, error) {\n\tif common.IsNullish(v) {\n\t\treturn 0, errors.New(\"cannot be null or undefined\")\n\t}\n\n\t// We initially tried using `ExportTo` with a int64 value argument, however\n\t// this led to a string passed as argument not being an error.\n\t// Thus, we explicitly check that the value is a number, by comparing\n\t// its export type to the type of an int64.\n\tif v.ExportType().Kind() != reflect.Int64 {\n\t\treturn 0, errors.New(\"must be a number\")\n\t}\n\n\treturn v.ToInteger(), nil\n}\n","sourceCodeStart":326,"sourceCodeEnd":357,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/fs/module.go#L326-L357","documentation":"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\".","triggerScenarios":"file.seek(0) with the whence argument omitted (it is mandatory); file.seek(null, SeekMode.Start); passing undefined explicitly for either argument.","commonSituations":"Assuming Node.js-style optional position arguments; porting code that used a single-argument seek; sparse call sites where whence is conditionally passed.","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)"],"exampleFix":"// before\nawait file.seek(1024);\n\n// after\nimport { SeekMode } from 'k6/experimental/fs';\nawait file.seek(1024, SeekMode.Start);","handlingStrategy":"validation","validationCode":"import { SeekMode } from 'k6/experimental/fs';\n\nfunction seekTo(file, offset, whence = SeekMode.Start) {\n  if (offset === null || offset === undefined || whence === null || whence === undefined) {\n    throw new TypeError('seek requires a numeric offset and a SeekMode whence');\n  }\n  return file.seek(offset, whence);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["fs","seek","validation","arguments"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}