grafana/k6 · error

cannot be null or undefined

Error message

cannot be null or undefined

What it means

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.

Solutions

  1. Always pass both arguments explicitly: file.seek(0, SeekMode.Start).
  2. Import SeekMode from 'k6/experimental/fs' and use its constants (Start/Current/End) instead of hand-rolled values.
  3. Validate config-derived offsets before the call: if (offset == null) throw new Error('offset missing').

Example fix

// before
const pos = await file.seek(null, SeekMode.Start); // rejects

// after
const pos = await file.seek(0, SeekMode.Start);
Defensive patterns

Strategy: type-guard

Validate before calling

function seekFile(file, offset, whence) {
  if (offset == null || whence == null) {
    throw new TypeError('seek() requires explicit non-null offset and whence');
  }
  return file.seek(offset, whence);
}

Type guard

const isSeekArgs = (offset, whence) => offset != null && whence != null;

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Must be a positive integer", "Invalid value", "Unsupported": the invalid-argument-value error family, when a library rejects the value you pass — this error's family across 35 libraries.

Related errors


AI-assisted analysis of grafana/k6@01ffac6f24 (2026-08-18). Data as JSON: /api/errors/ffd3534aec4bf048. Report an issue: GitHub.

Appendix: 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 01ffac6f24)