{"record":{"id":"7a4715bdc7a94aec","repo":"apache/beam","slug":"one-or-more-errorhandlers-aren-t-closed-and-this-pipeline","errorCode":null,"errorMessage":"One or more ErrorHandlers aren't closed, and this pipeline cannot be run. See the ErrorHandler documentation for expected usage","messagePattern":"One or more ErrorHandlers aren't closed, and this pipeline cannot be run\\. See the ErrorHandler documentation for expected usage","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/core/src/main/java/org/apache/beam/sdk/Pipeline.java","lineNumber":737,"sourceCode":"    public String apply(@Nonnull final Map.Entry<String, Collection<PTransform<?, ?>>> input) {\n      return input.getKey();\n    }\n  }\n\n  private static class IsUnique<K, V> implements Predicate<Map.Entry<K, Collection<V>>> {\n    @SuppressFBWarnings(\n        value = \"NP_METHOD_PARAMETER_TIGHTENS_ANNOTATION\",\n        justification = \"https://github.com/google/guava/issues/920\")\n    @Override\n    public boolean apply(@Nonnull final Map.Entry<K, Collection<V>> input) {\n      return input != null && input.getValue().size() == 1;\n    }\n  }\n\n  private void validateErrorHandlers() {\n    for (ErrorHandler<?, ?> errorHandler : errorHandlers) {\n      if (!errorHandler.isClosed()) {\n        throw new IllegalStateException(\n            \"One or more ErrorHandlers aren't closed, and this pipeline \"\n                + \"cannot be run. See the ErrorHandler documentation for expected usage\");\n      }\n    }\n  }\n}\n","sourceCodeStart":719,"sourceCodeEnd":744,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/core/src/main/java/org/apache/beam/sdk/Pipeline.java#L719-L744","documentation":"Before running, Pipeline.validateErrorHandlers() verifies that every ErrorHandler registered on the pipeline has been closed. An unclosed handler means error output (e.g. a write sink attached to bad-record routing) was never finalized, so run() throws this IllegalStateException to prevent silently dropping error records.","triggerScenarios":"Calling pipeline.run() while an ErrorHandler obtained via pipeline.registerErrorHandler(...) / construction is still open — i.e. the user never called errorHandler.close() (which attaches the error-collection sink) after wiring transforms.","commonSituations":"Using error handlers for write failures (e.g. BigQuery/Nio bad-record routing) and forgetting the close() step; early returns or exceptions in pipeline-construction code that skip the close call.","solutions":["Call close() on every registered ErrorHandler after attaching its sink and before pipeline.run().","Use try/finally around pipeline construction so close() runs even if intermediate steps throw.","If the handler is genuinely unused, remove its registration from the pipeline instead of leaving it open.","Review the ErrorHandler Javadoc usage pattern: create, wire into transforms, close, then run."],"exampleFix":"// before\n// ErrorHandler<PCollectionTuple, ? > h = pipeline.registerErrorHandler(...); pipeline.run(); // throws\n// after\n// ErrorHandler<PFileSystem, ? > h = pipeline.registerErrorHandler(...); ... h.close(); pipeline.run();","handlingStrategy":"try-catch","validationCode":"// Java: verify all handlers are closed before run\nfor (ErrorHandler<?, ?> h : registeredHandlers) {\n  if (!h.isClosed()) throw new IllegalStateException(\"Handler not closed: \" + h);\n}","typeGuard":null,"tryCatchPattern":"ErrorHandler<...> h = pipeline.registerErrorHandler(...);\ntry {\n  // wire transforms using h\n  h.close();\n  pipeline.run();\n} catch (IllegalStateException e) {\n  if (e.getMessage().contains(\"ErrorHandlers aren't closed\")) {\n    h.close();\n    pipeline.run(); // retry once closed\n  } else { throw e; }\n}","preventionTips":["Adopt the create -> wire -> close -> run pattern from the ErrorHandler Javadoc","Wrap pipeline construction in try/finally ensuring close()","Grep for registerErrorHandler call sites and pair each with close()"],"tags":["java","beam","error-handler","lifecycle","validation"],"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"}