{"id":"ad7d2fd411938a72","repo":"pika/pika","slug":"name-must-be-0-but-got-value","errorCode":null,"errorMessage":"{name} must be >= 0, but got {value}","messagePattern":"(.+?) must be >= 0, but got (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"pika/validators.py","lineNumber":65,"sourceCode":"    if callable(callback):\n        # nowait=False\n        return False\n    raise TypeError('completion callback must be callable if not None')\n\n\ndef zero_or_greater(name: str, value: int) -> None:\n    \"\"\"\n    Verify that value is zero or greater.\n\n    If not, 'name' will be used in error message\n\n    :param name: value name to use in error message\n    :param value: value to check\n    :raises: ValueError\n    \"\"\"\n    if int(value) < 0:\n        errmsg = f'{name} must be >= 0, but got {value}'\n        raise ValueError(errmsg)\n","sourceCodeStart":47,"sourceCodeEnd":66,"githubUrl":"https://github.com/pika/pika/blob/295ad9e5795061d759b694ab1fcb33cd381d8c49/pika/validators.py#L47-L66","documentation":"validators.zero_or_greater raises ValueError when an integer parameter is negative. It is used for AMQP QoS parameters: prefetch_size and prefetch_count in channel.basic_qos (channel.py:560-561). The AMQP spec requires these as non-negative integers, so pika guards before sending the frame. Note it casts with int(value), so non-numeric values raise their own TypeError/ValueError from int().","triggerScenarios":"Calling channel.basic_qos(prefetch_count=-1) or channel.basic_qos(prefetch_size=-100). Any negative value for either prefetch parameter triggers it; prefetch_count=0 means unlimited and is allowed.","commonSituations":"Computing prefetch from a formula that can go negative (e.g. capacity - inflight when inflight > capacity); defaulting an unset config to -1 and forwarding it; misunderstanding that 0 means unlimited and using -1 to mean 'no limit'.","solutions":["Clamp the computed value to max(0, desired) before calling basic_qos.","Use 0 for 'unlimited' prefetch, never a negative number.","Validate config-sourced prefetch values with an isinstance/>=0 check before passing them in."],"exampleFix":"# before\nchannel.basic_qos(prefetch_count=capacity - in_flight)  # can be negative\n# after\nchannel.basic_qos(prefetch_count=max(0, capacity - in_flight))","handlingStrategy":"validation","validationCode":"prefetch_count = max(0, int(prefetch_count))\nprefetch_size = max(0, int(prefetch_size))\nchannel.basic_qos(prefetch_size=prefetch_size, prefetch_count=prefetch_count)","typeGuard":"def is_nonneg_int(v: int) -> bool:\n    return isinstance(v, int) and v >= 0","tryCatchPattern":null,"preventionTips":["Clamp computed prefetch values with max(0, value).","Use 0 for unlimited; never use -1 as a sentinel."],"tags":["validation","value-error","qos","channel"],"analyzedSha":"295ad9e5795061d759b694ab1fcb33cd381d8c49","analyzedAt":"2026-08-04T20:47:41.389Z","schemaVersion":2}