{"record":{"id":"88ee5334a70ac2c2","repo":"apache/beam","slug":"cannot-skip-negative-number-of-header-lines-d","errorCode":null,"errorMessage":"Cannot skip negative number of header lines: %d","messagePattern":"Cannot skip negative number of header lines: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/textio.py","lineNumber":154,"sourceCode":"        delimiter, can also escape itself.\n    Raises:\n      ValueError: if skip_lines is negative.\n\n    Please refer to documentation in class `ReadFromText` for the rest\n    of the arguments.\n    \"\"\"\n    super().__init__(\n        file_pattern,\n        min_bundle_size,\n        compression_type=compression_type,\n        validate=validate)\n\n    self._strip_trailing_newlines = strip_trailing_newlines\n    self._compression_type = compression_type\n    self._coder = coder\n    self._buffer_size = buffer_size\n    if skip_header_lines < 0:\n      raise ValueError(\n          'Cannot skip negative number of header lines: %d' % skip_header_lines)\n    elif skip_header_lines > 10:\n      _LOGGER.warning(\n          'Skipping %d header lines. Skipping large number of header '\n          'lines might significantly slow down processing.')\n    self._skip_header_lines = skip_header_lines\n    self._header_matcher, self._header_processor = header_processor_fns\n    if delimiter is not None:\n      if not isinstance(delimiter, bytes) or len(delimiter) == 0:\n        raise ValueError('Delimiter must be a non-empty bytes sequence.')\n      if self._is_self_overlapping(delimiter):\n        raise ValueError('Delimiter must not self-overlap.')\n    self._delimiter = delimiter\n    if escapechar is not None:\n      if not (isinstance(escapechar, bytes) and len(escapechar) == 1):\n        raise ValueError(\n            \"escapechar must be bytes of size 1: '%s'\" % escapechar)\n    self._escapechar = escapechar","sourceCodeStart":136,"sourceCodeEnd":172,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/textio.py#L136-L172","documentation":"ReadFromText's __init__ validates skip_header_lines and raises this ValueError when a negative value is passed. Skipping a negative number of header lines is meaningless, so it is rejected at construction time; values above 10 only produce a performance warning.","triggerScenarios":"Creating ReadFromText(file_pattern, skip_header_lines=-1) (or any negative int), often from a config value, CLI flag, or computed expression like n-1 that underflows.","commonSituations":"YAML/pipeline options where skip_header_lines defaults to -1 meaning 'unset'; arithmetic like header_count-1 with header_count=0; typos passing skip_footer=-1 style values to the wrong parameter.","solutions":["Pass 0 (the default) or a positive integer for skip_header_lines.","Validate/sanitize the value before constructing: max(0, int(configured_value)).","Fix the pipeline option default so 'unset' maps to 0 rather than -1.","If headers must be conditionally skipped, branch between ReadFromText(..., skip_header_lines=0) and the skipping variant instead of negating."],"exampleFix":"// before\nReadFromText('data.csv', skip_header_lines=-1)\n// after\nReadFromText('data.csv', skip_header_lines=max(0, requested_header_lines))","handlingStrategy":"validation","validationCode":"if not isinstance(skip_header_lines, int) or skip_header_lines < 0:\n    raise ValueError(f'skip_header_lines must be >= 0, got {skip_header_lines!r}')","typeGuard":"def is_valid_skip_header_lines(v):\n    return isinstance(v, int) and not isinstance(v, bool) and v >= 0","tryCatchPattern":"try:\n    transform = ReadFromText(file_pattern, skip_header_lines=skip_header_lines)\nexcept ValueError as e:\n    if 'skip negative number of header lines' in str(e):\n        logging.error('Bad skip_header_lines: %s', skip_header_lines)\n        transform = ReadFromText(file_pattern, skip_header_lines=0)","preventionTips":["Default pipeline options to 0, not -1, for 'no skipping'","Sanitize external config with max(0, int(value)) before constructing the transform","Watch for arithmetic underflow like header_count - 1 when header_count can be 0"],"tags":["python","apache-beam","textio","constructor-argument","validation"],"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-20T03:17:13.778Z"}