{"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/01ffac6f245854c1b8adc6a69857c76a15f90022/internal/js/modules/k6/experimental/fs/module.go#L334-L357","documentation":"exportInt requires the JS value's export type to be exactly reflect.Int64 - a genuine number. Strings like '10', booleans, or objects all fail with 'must be a number' (the source comment explains ExportTo was tried first but let strings slip through, hence the strict check). File.seek prefixes it, e.g. 'seek() failed; reason: the whence argument must be a number'.","triggerScenarios":"file.seek('10', SeekMode.Start) or file.seek(0, '0') - numeric strings read from JSON config, CSV, URL params, or parseInt-less user input. Note the whence check then also validates the value against the three SeekMode constants, so out-of-range numbers fail with a different 'must be a SeekMode' error.","commonSituations":"Offsets loaded from a JSON/CSV config file arrive as strings in JS; passing process.env or CLI-supplied (--env) values, which are strings in k6; copy-pasting code from a language where seek takes an enum name string.","solutions":["Convert explicitly with Number() or parseInt(): file.seek(Number(cfg.offset), SeekMode.Start).","Use literal numbers or computed numeric values for both arguments.","Remember k6 --env values are strings: wrap them with Number() at the call site."],"exampleFix":"// before\nconst off = __ENV.SEEK_OFFSET; // string like '128'\nawait file.seek(off, SeekMode.Start); // rejects: must be a number\n\n// after\nawait file.seek(Number(__ENV.SEEK_OFFSET), SeekMode.Start);","handlingStrategy":"type-guard","validationCode":"const isInt = (v) => Number.isInteger(Number(v)) && v !== null && v !== '' && typeof v !== 'string';\n// simpler strict check:\nconst isStrictInt = (v) => typeof v === 'number' && Number.isInteger(v);\nif (!isStrictInt(offset)) throw new TypeError('offset must be a number');","typeGuard":"const isStrictInt = (v) => typeof v === 'number' && Number.isInteger(v);","tryCatchPattern":null,"preventionTips":["Wrap config/env-sourced values with Number() at the boundary, not at the call site.","Use SeekMode.Start/Current/End constants - never strings or magic numbers."],"tags":["k6","fs","seek","type-error","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"}