grafana/k6 · error

invalid maxReceiveSize value: '%#v, it needs to be a positiv

Error message

invalid maxReceiveSize value: '%#v, it needs to be a positive integer

What it means

After the integer check, newConnectParams rejects negative maxReceiveSize values (params.go:190): the receive limit cannot be negative, and 0 means no limit. (The error text also has a cosmetic missing closing quote after the value.)

Source

Thrown at internal/js/modules/k6/grpc/params.go:191

			result.UseReflectionProtocol, ok = v.(bool)
			if !ok {
				return result, fmt.Errorf("invalid reflect value: '%#v', it needs to be boolean", v)
			}
		case "reflectMetadata":
			md, err := newMetadata(params.Get(k))
			if err != nil {
				return result, fmt.Errorf("invalid reflectMetadata param: %w", err)
			}

			result.ReflectionMetadata = md
		case "maxReceiveSize":
			var ok bool
			result.MaxReceiveSize, ok = v.(int64)
			if !ok {
				return result, fmt.Errorf("invalid maxReceiveSize value: '%#v', it needs to be an integer", v)
			}
			if result.MaxReceiveSize < 0 {
				return result, fmt.Errorf("invalid maxReceiveSize value: '%#v, it needs to be a positive integer", v)
			}
		case "maxSendSize":
			var ok bool
			result.MaxSendSize, ok = v.(int64)
			if !ok {
				return result, fmt.Errorf("invalid maxSendSize value: '%#v', it needs to be an integer", v)
			}
			if result.MaxSendSize < 0 {
				return result, fmt.Errorf("invalid maxSendSize value: '%#v, it needs to be a positive integer", v)
			}
		case "tls":
			if err := parseConnectTLSParam(result, v); err != nil {
				return result, err
			}
		case "authority":
			var ok bool
			result.Authority, ok = v.(string)
			if !ok {

View on GitHub (pinned to 93accf6570)

Solutions

  1. Use 0 for no explicit limit
  2. Clamp sentinel -1 values to 0 before calling connect
  3. Re-check the computation that produced the negative number

Example fix

// before
client.connect(addr, { maxReceiveSize: -1 }); // -1 is not 'unlimited'

// after
client.connect(addr, { maxReceiveSize: 0 }); // 0 = no explicit limit
Defensive patterns

Strategy: validation

Validate before calling

if (connectParams.maxReceiveSize !== undefined) {
  const n = connectParams.maxReceiveSize;
  if (typeof n !== 'number' || !Number.isInteger(n) || n < 0) {
    throw new Error(`maxReceiveSize must be a non-negative integer, got ${n} (use 0 for no limit)`);
  }
}
client.connect(addr, connectParams);

Type guard

function isByteSize(v) {
  return typeof v === 'number' && Number.isInteger(v) && v >= 0;
}

Prevention

When it happens

Trigger: connect(addr, { maxReceiveSize: -1 }) — typically an attempt to mean 'unlimited', or a -1 'not set' sentinel leaking from config/code into the params object.

Common situations: Configs using -1 as the 'unlimited' convention; arithmetic that computes a size by subtraction and underflows to a negative number.

Related errors


AI-assisted analysis of grafana/k6@93accf6570 (2026-08-15). Data as JSON: /api/errors/1c5eb9cbb7eb60ad. Report an issue: GitHub.