{"record":{"id":"2b622df4a7e41da8","repo":"apache/beam","slug":"empty-match-for-pattern-s-disallowed","errorCode":null,"errorMessage":"Empty match for pattern %s. Disallowed.","messagePattern":"Empty match for pattern (.+?)\\. Disallowed\\.","errorType":"exception","errorClass":"BeamIOError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/fileio.py","lineNumber":178,"sourceCode":"    elif setting == EmptyMatchTreatment.DISALLOW:\n      return False\n    else:\n      raise ValueError(setting)\n\n\nclass _MatchAllFn(beam.DoFn):\n  def __init__(self, empty_match_treatment):\n    self._empty_match_treatment = empty_match_treatment\n\n  def process(self, file_pattern: str) -> list[filesystem.FileMetadata]:\n    # TODO: Should we batch the lookups?\n    match_results = filesystems.FileSystems.match([file_pattern])\n    match_result = match_results[0]\n\n    if (not match_result.metadata_list and\n        not EmptyMatchTreatment.allow_empty_match(file_pattern,\n                                                  self._empty_match_treatment)):\n      raise BeamIOError(\n          'Empty match for pattern %s. Disallowed.' % file_pattern)\n\n    return match_result.metadata_list\n\n\nclass MatchFiles(beam.PTransform):\n  \"\"\"Matches a file pattern using ``FileSystems.match``.\n\n  This ``PTransform`` returns a ``PCollection`` of matching files in the form\n  of ``FileMetadata`` objects.\"\"\"\n  def __init__(\n      self,\n      file_pattern: str,\n      empty_match_treatment=EmptyMatchTreatment.ALLOW_IF_WILDCARD):\n    self._file_pattern = file_pattern\n    self._empty_match_treatment = empty_match_treatment\n\n  def expand(self, pcoll) -> beam.PCollection[filesystem.FileMetadata]:","sourceCodeStart":160,"sourceCodeEnd":196,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/fileio.py#L160-L196","documentation":"_MatchAllFn.process raises BeamIOError when the glob pattern matched zero files and the configured EmptyMatchTreatment disallows empty matches (default). Beam refuses to continue silently with no input files so the pipeline surfaces the problem instead of producing empty output.","triggerScenarios":"Running MatchFiles/MatchAll with a pattern that matches nothing while empty_match_treatment is DISALLOW or ALLOW_IF_WILDCARD with no '*' in the pattern; files not yet written at runtime; wrong bucket/prefix.","commonSituations":"Streaming or scheduled pipelines whose input directory is momentarily empty; typo'd pattern; permissions limiting the listing; tests against empty temp dirs.","solutions":["Fix the pattern or ensure files exist before the pipeline reads","Pass empty_match_treatment=EmptyMatchTreatment.ALLOW to tolerate zero matches","Use ALLOW_IF_WILDCARD and include a wildcard in the pattern","Guard with FileSystems.match first if you need custom handling"],"exampleFix":"// before\np | MatchAll('gs://b/inbox/*', empty_match_treatment=EmptyMatchTreatment.DISALLOW)\n// after\nfrom apache_beam.io.fileio import EmptyMatchTreatment\np | MatchAll('gs://b/inbox/*', empty_match_treatment=EmptyMatchTreatment.ALLOW)","handlingStrategy":"try-catch","validationCode":"from apache_beam.io.filesystems import FileSystems\nif not FileSystems.match([pattern], limits=[1])[0].metadata_list:\n    logging.warning('Pattern matches no files: %s', pattern)","typeGuard":null,"tryCatchPattern":"from apache_beam.io import fileio\ntry:\n    p | 'match' >> fileio.MatchAll(pattern, empty_match_treatment=EmptyMatchTreatment.ALLOW)\nexcept Exception as e:\n    if isinstance(e, fileio.BeamIOError) and 'Empty match' in str(e):\n        logging.warning('No files matched %s', pattern)\n    else:\n        raise","preventionTips":["Choose an explicit EmptyMatchTreatment matching your pipeline's semantics","For scheduled pipelines, ensure upstream writes complete before reads","Preflight the pattern with FileSystems.match in a dry-run step"],"tags":["io","file-pattern","empty-match"],"backgroundTag":"empty-result-set","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"}