Skip to content

Commit

Permalink
Adjust ConstraintAction error messages
Browse files Browse the repository at this point in the history
The errors will now correctly distinguish between a plan never being simulated and a specified sim dataset not existing.
Additionally, the serialializer for SimDatasetMismatch now refers to the correct extension.
  • Loading branch information
Mythicaeda committed Oct 4, 2023
1 parent a491c5a commit f597278
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
18 changes: 16 additions & 2 deletions e2e-tests/src/tests/bindings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,20 @@ test.describe('Merlin Bindings', () => {
expect(response.status()).toEqual(404);
expect((await response.json()).message).toEqual('no such plan');

// Returns a 404 if the SimulationDataset id is invalid
// message is "input mismatch exception"
response = await request.post(`${urls.MERLIN_URL}/constraintViolations`, {
data: {
action: {name: "check_constraints"},
input: {planId: plan_id, simulationDatasetId: -1},
request_query: "",
session_variables: admin.session}});
expect(response.status()).toEqual(404);
expect((await response.json())).toEqual({
message: "input mismatch exception",
cause: "simulation dataset with id `-1` does not exist"
});

// Returns a 403 if unauthorized
response = await request.post(`${urls.MERLIN_URL}/constraintViolations`, {
data: {
Expand All @@ -204,7 +218,7 @@ test.describe('Merlin Bindings', () => {
expect(response.status()).toEqual(404);
expect((await response.json())).toEqual({
message: "input mismatch exception",
cause: "no simulation datasets found for plan id " + plan_id
cause: "plan with id " + plan_id +" has not yet been simulated at its current revision"
});

// Returns a 404 if given an invalid simulation dataset id
Expand All @@ -218,7 +232,7 @@ test.describe('Merlin Bindings', () => {
session_variables: admin.session}});
expect(response.status()).toEqual(404);
expect((await response.json())).toEqual({
message: "input mismatch exception",
message: "simulation dataset mismatch exception",
cause: "Simulation Dataset with id `" + invalidSimDatasetId + "` does not belong to Plan with id `"+plan_id+"`"
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public static JsonValue serializeInputMismatchException(final InputMismatchExcep

public static JsonValue serializeSimulationDatasetMismatchException(final SimulationDatasetMismatchException ex){
return Json.createObjectBuilder()
.add("message", "input mismatch exception")
.add("message", "simulation dataset mismatch exception")
.add("cause", ex.getMessage())
.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,18 @@ public List<ConstraintResult> getViolations(final PlanId planId, final Optional<
throws NoSuchPlanException, MissionModelService.NoSuchMissionModelException, SimulationDatasetMismatchException {
final var plan = this.planService.getPlanForValidation(planId);
final Optional<SimulationResultsHandle> resultsHandle$;
final SimulationDatasetId simDatasetId;
if (simulationDatasetId.isPresent()) {
resultsHandle$ = this.simulationService.get(planId, simulationDatasetId.get());
simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("simulation dataset with id `" + simulationDatasetId.get().id() + "` does not exist"));
} else {
final var revisionData = this.planService.getPlanRevisionData(planId);
resultsHandle$ = this.simulationService.get(planId, revisionData);
simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("plan with id " + planId.id() +" has not yet been simulated at its current revision"));
}


Expand All @@ -68,9 +75,6 @@ public List<ConstraintResult> getViolations(final PlanId planId, final Optional<
throw new RuntimeException("Assumption falsified -- mission model for existing plan does not exist");
}

final var simDatasetId = resultsHandle$
.map(SimulationResultsHandle::getSimulationDatasetId)
.orElseThrow(() -> new InputMismatchException("no simulation datasets found for plan id " + planId.id()));
final var violations = new HashMap<Long, ConstraintResult>();

final var validConstraintRuns = this.constraintService.getValidConstraintRuns(constraintCode.values().stream().toList(), simDatasetId);
Expand Down

0 comments on commit f597278

Please sign in to comment.