Skip to content

Commit

Permalink
fix error msg for invalid operation io bindings (#1728)
Browse files Browse the repository at this point in the history
Fixes issue #1719, which pointed out that error messages when operation
input targeted structures with the `@output` trait (and vice-versa) were
incorrect. The error message was built using the operation <-> target
relationship name for the name of the invalid trait, instead of using
it as the operation property which targeted an invalid shape.

The error message was also updated to include the shape id of the
targeted shape, and existing tests were updated to reflect that
change.
  • Loading branch information
milesziemer authored Apr 10, 2023
1 parent 75e4b4d commit 44e3fdf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private void validateInputOutput(
}
} else if (relName.equals(invalid)) {
// Input shouldn't reference output, and vice versa.
events.add(emitInvalidOperationBinding(rel.getShape(), descriptor, invalid));
events.add(emitInvalidOperationBinding(rel.getShape(), shape, relName, descriptor));
} else if (rel.getRelationshipType() == RelationshipType.MEMBER_TARGET) {
// Members can't target shapes marked with @input or @output.
events.add(emitInvalidMemberRef(rel.getShape().asMemberShape().get(), descriptor));
Expand All @@ -109,12 +109,19 @@ private void validateInputOutput(
}
}

private ValidationEvent emitInvalidOperationBinding(Shape operation, String property, String invalid) {
private ValidationEvent emitInvalidOperationBinding(
Shape operation,
Shape target,
String property,
String invalid
) {
return ValidationEvent.builder()
.id(OPERATION_INPUT_OUTPUT_MISUSE)
.severity(Severity.ERROR)
.shape(operation)
.message("Operation " + property + " cannot target structures marked with the @" + invalid + " trait")
.message(String.format(
"Operation `%s` cannot target structures marked with the `@%s` trait: `%s`",
property, invalid, target.getId()))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[ERROR] smithy.example#GetFoo: Operation input cannot target structures marked with the @output trait | OperationInputOutputMisuse
[ERROR] smithy.example#GetFoo: Operation output cannot target structures marked with the @input trait | OperationInputOutputMisuse
[ERROR] smithy.example#GetFoo: Operation `input` cannot target structures marked with the `@output` trait: `smithy.example#GetFooOutput` | OperationInputOutputMisuse
[ERROR] smithy.example#GetFoo: Operation `output` cannot target structures marked with the `@input` trait: `smithy.example#GetFooInput` | OperationInputOutputMisuse

0 comments on commit 44e3fdf

Please sign in to comment.