{"record":{"id":"3ecd3b29064fc1d7","repo":"apache/beam","slug":"collectingerrorhandler-requires-the-output-to-be-retrieved","errorCode":null,"errorMessage":"CollectingErrorHandler requires the output to be retrieved. Initialized at %s","messagePattern":"CollectingErrorHandler requires the output to be retrieved\\. Initialized at (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/transforms/error_handling.py","lineNumber":123,"sourceCode":"\nclass CollectingErrorHandler(ErrorHandler):\n  \"\"\"An ErrorHandler that simply collects all errors for further processing.\n\n  This ErrorHandler requires the set of errors be retrieved via `output()`\n  and consumed (or explicitly discarded).\n  \"\"\"\n  def __init__(self):\n    super().__init__(_IdentityPTransform())\n    self._creation_traceback = traceback.format_stack()[-2]\n    self._output_accessed = False\n\n  def output(self):\n    self._output_accessed = True\n    return super().output()\n\n  def verify_closed(self):\n    if not self._output_accessed:\n      raise RuntimeError(\n          \"CollectingErrorHandler requires the output to be retrieved. \"\n          \"Initialized at %s\" % self._creation_traceback)\n    return super().verify_closed()\n","sourceCodeStart":105,"sourceCodeEnd":127,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/transforms/error_handling.py#L105-L127","documentation":"CollectingErrorHandler accumulates error records in memory, which are only materialized when output() is called; calling output() also marks the handler as having had its output accessed. verify_closed() raises this RuntimeError if the handler closed without output() ever being read, because the collected error records would otherwise be silently discarded.","triggerScenarios":"Using CollectingErrorHandler as a context manager (or closing it) but never calling handler.output() before the pipeline is built.","commonSituations":"Copying error-handling boilerplate from stateless handlers that don't require output retrieval, or exiting the with-block on an exception path before reading the collected records.","solutions":["Call handler.output() inside the with-block after applying the transform, and wire the result into the pipeline.","Use a different ErrorHandler (e.g. a sink-writing handler) if you don't need to read the collected records.","Inspect the 'initialized at' traceback to find the unused handler."],"exampleFix":"# before\nwith error_handling(CollectingErrorHandler()) as handler:\n  pcoll.with_exception_handling(handler, ...)\n# after\nwith error_handling(CollectingErrorHandler()) as handler:\n  pcoll.with_exception_handling(handler, ...)\n  handler.output()  # consume collected errors","handlingStrategy":"validation","validationCode":"assert getattr(handler, '_output_accessed', False), 'CollectingErrorHandler.output() must be called before close'","typeGuard":"def output_consumed(handler) -> bool:\n    return bool(getattr(handler, '_output_accessed', False))","tryCatchPattern":"try:\n    pipeline.run()\nexcept RuntimeError as e:\n    if 'requires the output to be retrieved' in str(e):\n        add_output_call(e)  # wire handler.output() into the pipeline\n    raise","preventionTips":["Call handler.output() inside the with-block right after with_exception_handling.","Don't reuse stateless-handler templates for CollectingErrorHandler.","If records aren't needed, switch to a sink-based error handler."],"tags":["python","apache-beam","pipeline-construction","unused-result"],"backgroundTag":"invalid-state-transition","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"}