{"record":{"id":"118e375a6e5472e2","repo":"apache/beam","slug":"expected-0-or-1-got-s","errorCode":null,"errorMessage":"Expected 0 or 1, got %s","messagePattern":"Expected 0 or 1, got (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/coders/coder_impl.py","lineNumber":726,"sourceCode":"\n  def decode(self, encoded):\n    return encoded\n\n\nclass BooleanCoderImpl(CoderImpl):\n  \"\"\"For internal use only; no backwards-compatibility guarantees.\n\n  A coder for bool objects.\"\"\"\n  def encode_to_stream(self, value, out, nested):\n    out.write_byte(1 if value else 0)\n\n  def decode_from_stream(self, in_stream, nested):\n    value = in_stream.read_byte()\n    if value == 0:\n      return False\n    elif value == 1:\n      return True\n    raise ValueError(\"Expected 0 or 1, got %s\" % value)\n\n  def encode(self, value):\n    return b'\\x01' if value else b'\\x00'\n\n  def decode(self, encoded):\n    value = ord(encoded)\n    if value == 0:\n      return False\n    elif value == 1:\n      return True\n    raise ValueError(\"Expected 0 or 1, got %s\" % value)\n\n  def estimate_size(self, unused_value, nested=False):\n    # Note that booleans are encoded the same way regardless of nesting.\n    return 1\n\n\nclass MapCoderImpl(StreamCoderImpl):","sourceCodeStart":708,"sourceCodeEnd":744,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/coders/coder_impl.py#L708-L744","documentation":"BoolCoder's decode_from_stream expects the wire byte for a boolean to be exactly 0x00 (False) or 0x01 (True). Any other byte means the stream is not a valid boolean encoding — usually corrupted, truncated, or misaligned data — so it raises ValueError('Expected 0 or 1, got %s').","triggerScenarios":"decode_from_stream reads a byte from the input stream whose value is neither 0 nor 1: reading a stream produced by a different coder/version, reading past a record boundary (desync), or decoding corrupted files.","commonSituations":"Resuming pipelines from staged data written by another Beam version; custom coders that mis-encode lengths causing the boolean decoder to land mid-record; manually hand-crafted or edited encoded blobs.","solutions":["Regenerate the data with the same Beam version rather than decoding stale/cross-version payloads.","Check for a custom coder consuming too few/many bytes upstream, desynchronizing the stream.","Clear cached/staged state directories and rerun the pipeline.","Validate the source data file/stream integrity before decoding."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"def is_valid_bool_payload(b: bytes) -> bool:\n    return isinstance(b, (bytes, bytearray)) and len(b) == 1 and b[0] in (0, 1)","typeGuard":null,"tryCatchPattern":"try:\n    flag = coder.decode_from_stream(in_stream, nested=True)\nexcept ValueError as e:\n    logger.error(\"Stream desync while reading bool: %s\", e)\n    raise DataCorruptionError from e","preventionTips":["Keep Beam versions consistent between encode and decode","Fix custom coders that mis-size preceding records to avoid stream desync","Avoid decoding manually crafted byte payloads"],"tags":["apache-beam","python","coder","deserialization","corruption"],"backgroundTag":"invalid-argument-value","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}