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

fix error msg for invalid operation io bindings #1728

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
fix error msg for invalid operation io bindings
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 committed Apr 10, 2023
commit 50a5b59ebca88e55d5291c152cbfe21efd6d294f
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