{"record":{"id":"13d5a4c690a4ce1f","repo":"grafana/k6","slug":"must-be-a-number","errorCode":null,"errorMessage":"must be a number","messagePattern":"must be a number","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/modules/k6/experimental/fs/module.go","lineNumber":352,"sourceCode":"\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":334,"sourceCodeEnd":357,"githubUrl":"https://github.com/grafana/k6/blob/93accf6570dcd306ca5e99cc44c393ee3797761b/internal/js/modules/k6/experimental/fs/module.go#L334-L357","documentation":"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\".","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nawait file.seek(offsetStr, 'Start');\n\n// after\nimport { SeekMode } from 'k6/experimental/fs';\nawait file.seek(Number(offsetStr), SeekMode.Start);","handlingStrategy":"validation","validationCode":"function isSeekArg(v) {\n  return typeof v === 'number' && Number.isInteger(v);\n}\n\nif (!isSeekArg(offset) || !isSeekArg(whence)) throw new TypeError('seek arguments must be integers');\nawait file.seek(offset, whence);","typeGuard":"/** @param {unknown} v @returns {v is number} */\nconst isInt = (v) => typeof v === 'number' && Number.isInteger(v);","tryCatchPattern":null,"preventionTips":["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"],"tags":["fs","seek","type-coercion","validation"],"backgroundTag":null,"analyzedSha":"93accf6570dcd306ca5e99cc44c393ee3797761b","analyzedAt":"2026-08-15T21:23:27.118Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}