Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve ConstraintAction Error Messages #1177

Merged
merged 1 commit into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
mattdailis marked this conversation as resolved.
Show resolved Hide resolved
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);
mattdailis marked this conversation as resolved.
Show resolved Hide resolved
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
Loading