grafana/k6 · error

invalid maxSendSize value: '%#v, it needs to be a positive i

Error message

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

What it means

After the integer check, newConnectParams rejects negative maxSendSize values (params.go:199): the send 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:200

			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 {
				return result, fmt.Errorf("invalid authority value: '%#v', it needs to be a string", v)
			}
		default:
			return result, fmt.Errorf("unknown connect param: %q", k)
		}
	}

	return result, nil
}

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, { maxSendSize: -1 });

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

Strategy: validation

Validate before calling

if (connectParams.maxSendSize !== undefined) {
  const n = connectParams.maxSendSize;
  if (typeof n !== 'number' || !Number.isInteger(n) || n < 0) {
    throw new Error(`maxSendSize 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, { maxSendSize: -1 }) — a -1 'unlimited' or 'not set' convention leaking into the params object, or size arithmetic that underflowed.

Common situations: Configs using -1 as the 'unlimited' convention; computed limits (payload budget minus overhead) going negative for small budgets.

Related errors


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