{"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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/fs/module.go#L326-L357","documentation":"exportInt is the argument marshaller for File.seek(offset, whence) in k6/experimental/fs. It refuses null/undefined so that omitting an argument fails loudly instead of silently coercing to 0; the raw message is prefixed by the caller, producing 'seek() failed; reason: the offset argument cannot be null or undefined' (or 'the whence argument ...') as a promise rejection.","triggerScenarios":"file.seek(null, SeekMode.Start), file.seek(0, undefined), or file.seek() with missing arguments - any seek call where offset or whence is null/undefined. The rejection happens synchronously-ish before any actual seeking occurs.","commonSituations":"Porting Node stream code where seek-like calls have defaults; passing a variable that is undefined because of a typo or a failed lookup (e.g. config.offset missing); forgetting that whence is required, unlike some APIs where it defaults to SeekMode.Start.","solutions":["Always pass both arguments explicitly: file.seek(0, SeekMode.Start).","Import SeekMode from 'k6/experimental/fs' and use its constants (Start/Current/End) instead of hand-rolled values.","Validate config-derived offsets before the call: if (offset == null) throw new Error('offset missing')."],"exampleFix":"// before\nconst pos = await file.seek(null, SeekMode.Start); // rejects\n\n// after\nconst pos = await file.seek(0, SeekMode.Start);","handlingStrategy":"type-guard","validationCode":"function seekFile(file, offset, whence) {\n  if (offset == null || whence == null) {\n    throw new TypeError('seek() requires explicit non-null offset and whence');\n  }\n  return file.seek(offset, whence);\n}","typeGuard":"const isSeekArgs = (offset, whence) => offset != null && whence != null;","tryCatchPattern":null,"preventionTips":["Always pass both seek arguments; there are no defaults.","Default the whence yourself: (whence ?? SeekMode.Start) - but only after confirming that is the intended semantics."],"tags":["k6","fs","seek","validation","experimental"],"backgroundTag":"invalid-argument-value","analyzedSha":"01ffac6f245854c1b8adc6a69857c76a15f90022","analyzedAt":"2026-08-18T03:05:52.393Z","contentChangedAt":"2026-08-18T03:05:52.393Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}