{"record":{"id":"a2ef66e19da8d7a1","repo":"apache/beam","slug":"error-while-preparerun","errorCode":null,"errorMessage":"Error while prepareRun","messagePattern":"Error while prepareRun","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"sdks/java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/Plugin.java","lineNumber":121,"sourceCode":"  /**\n   * Calls {@link SubmitterLifecycle#prepareRun(Object)} method on the {@link #cdapPluginObj}\n   * passing needed {@param config} configuration object as a parameter. This method is needed for\n   * validating connection to the CDAP sink/source and performing initial tuning.\n   */\n  public void prepareRun() {\n    if (isUnbounded()) {\n      // Not needed for unbounded plugins\n      return;\n    }\n    if (cdapPluginObj == null) {\n      instantiateCdapPluginObj();\n    }\n    checkStateNotNull(cdapPluginObj, \"Cdap Plugin object can't be null!\");\n    try {\n      cdapPluginObj.prepareRun(getContext());\n    } catch (Exception e) {\n      LOG.error(\"Error while prepareRun\", e);\n      throw new IllegalStateException(\"Error while prepareRun\", e);\n    }\n    if (getPluginType().equals(PluginConstants.PluginType.SOURCE)) {\n      for (Map.Entry<String, String> entry :\n          getContext().getInputFormatProvider().getInputFormatConfiguration().entrySet()) {\n        getHadoopConfiguration().set(entry.getKey(), entry.getValue());\n      }\n    } else {\n      for (Map.Entry<String, String> entry :\n          getContext().getOutputFormatProvider().getOutputFormatConfiguration().entrySet()) {\n        getHadoopConfiguration().set(entry.getKey(), entry.getValue());\n      }\n      getHadoopConfiguration().set(MRJobConfig.ID, String.valueOf(1));\n    }\n  }\n\n  /** Creates an instance of {@link #cdapPluginObj} using {@link #pluginConfig}. */\n  private void instantiateCdapPluginObj() {\n    PluginConfig pluginConfig = getPluginConfig();","sourceCodeStart":103,"sourceCodeEnd":139,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/java/io/cdap/src/main/java/org/apache/beam/sdk/io/cdap/Plugin.java#L103-L139","documentation":"Plugin.prepareRun() delegates to the CDAP plugin's prepareRun(context). Any exception thrown by the plugin during preparation (authentication, connection, config validation) is caught, logged, and rethrown as IllegalStateException('Error while prepareRun') with the original cause attached.","triggerScenarios":"Calling CdapIO.read()/write() where the underlying plugin's prepareRun fails — e.g. bad credentials, unreachable instance, invalid plugin configuration.","commonSituations":"Wrong CDAP instance host/port/token; expired credentials; invalid plugin config values discovered during preparation; network/timeout to CDAP instance.","solutions":["Inspect the wrapped cause exception in the stack trace for the real failure.","Validate plugin configuration (host, port, auth token, dataset names) before running the pipeline.","Test connectivity to the CDAP instance with curl or the CDAP CLI.","Fix authentication/authorization credentials if the cause indicates auth errors."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// pre-flight: validate plugin config and connectivity\nCurl/CDAP CLI check: curl -H 'Authorization: Bearer $TOKEN' https://$CDAP_HOST:$PORT/v3/namespaces","typeGuard":null,"tryCatchPattern":"try { pipeline.run().waitUntilFinish(); } catch (IllegalStateException e) {\n  if (\"Error while prepareRun\".equals(e.getMessage())) {\n    Throwable cause = e.getCause(); // real plugin failure\n  }\n  throw e;\n}","preventionTips":["Always inspect getCause() for the underlying error.","Validate credentials and CDAP instance reachability pre-run.","Dry-run plugin configs in the CDAP UI first."],"tags":["java","apache-beam","cdap","plugin","preparation"],"backgroundTag":"api-request-failed","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"}