Skip to content

Commit

Permalink
Throw IllegalArgumentException when cancelJob failed with ValidationE…
Browse files Browse the repository at this point in the history
…xception

Signed-off-by: Tomoyuki Morita <[email protected]>
  • Loading branch information
ykmr1224 committed Sep 5, 2024
1 parent d5e13b4 commit c833dd9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,16 @@ public CancelJobRunResult cancelJobRun(
} catch (Throwable t) {
if (allowExceptionPropagation) {
throw t;
} else {
logger.error("Error while making cancel job request to emr:", t);
metricsService.incrementNumericalMetric(EMR_CANCEL_JOB_REQUEST_FAILURE_COUNT);
throw new RuntimeException(GENERIC_INTERNAL_SERVER_ERROR_MESSAGE);
}

logger.error("Error while making cancel job request to emr:", t);
metricsService.incrementNumericalMetric(EMR_CANCEL_JOB_REQUEST_FAILURE_COUNT);
if (t instanceof ValidationException) {
throw new IllegalArgumentException(
"The input fails to satisfy the constraints specified by AWS EMR"
+ " Serverless.");
}
throw new RuntimeException(GENERIC_INTERNAL_SERVER_ERROR_MESSAGE);
}
});
logger.info(String.format("Job : %s cancelled", cancelJobRunResult.getJobRunId()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,12 @@ void testCancelJobRunWithValidationException() {

RuntimeException runtimeException =
Assertions.assertThrows(
RuntimeException.class,
IllegalArgumentException.class,
() -> emrServerlessClient.cancelJobRun(EMRS_APPLICATION_ID, EMR_JOB_ID, false));

Assertions.assertEquals("Internal Server Error.", runtimeException.getMessage());
Assertions.assertEquals(
"The input fails to satisfy the constraints specified by AWS EMR Serverless.",
runtimeException.getMessage());
}

@Test
Expand Down

0 comments on commit c833dd9

Please sign in to comment.