Skip to content

Commit

Permalink
Fix regression that allowed suppressing ERROR
Browse files Browse the repository at this point in the history
There was a regression in #1890 that allowed ERROR events to be
suppressed. This was not intentional and we do not want to remove this
restriction. ERROR events indicate that the model is in an unusable
state because it violates a MUST in the spec or some other necessary
requirement to make it usable (like referring only to shapes that
exist).

New test cases have been added to guard against this regression in
the future.

Closes #2128
  • Loading branch information
mtdowling committed Feb 7, 2024
1 parent 8977f93 commit 764521f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ private static ValidationEvent modifyEventSeverity(
List<Suppression> suppressions,
List<SeverityOverride> severityOverrides
) {
// ERROR and SUPPRESSED events cannot be suppressed.
if (!event.getSeverity().canSuppress()) {
return event;
}

// Use a suppress trait if present.
if (event.getShapeId().isPresent()) {
ShapeId target = event.getShapeId().get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,18 @@

package software.amazon.smithy.model.knowledge;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import software.amazon.smithy.model.Model;
import software.amazon.smithy.model.shapes.MemberShape;
import software.amazon.smithy.model.shapes.OperationShape;
import software.amazon.smithy.model.shapes.ShapeId;
import software.amazon.smithy.model.validation.Severity;
import software.amazon.smithy.model.validation.ValidatedResult;
import software.amazon.smithy.model.validation.ValidatedResultException;

public class PropertyBindingIndexTest {

Expand Down Expand Up @@ -71,8 +69,6 @@ public void testIndex() {
assertTrue(index.doesMemberShapeRequireProperty(model.expectShape(
ShapeId.from("com.example#ChangeResourceOutput$id"), MemberShape.class)));

assertThat(vrmodel.getValidationEvents(Severity.SUPPRESSED), hasSize(1));
assertThat(vrmodel.getValidationEvents(Severity.SUPPRESSED).get(0).getId(),
equalTo("ResourceOperationInputOutput"));
Assertions.assertThrows(ValidatedResultException.class, () -> vrmodel.unwrap());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ERROR] foo.baz#MyString: Trait `idempotent` | TraitTarget
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
$version: "2"

metadata suppressions = [
{
namespace: "foo.baz"
id: "TraitTarget"
}
]

namespace foo.baz

@idempotent // < this is invalid
string MyString
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[ERROR] foo.baz#MyString: Trait `idempotent` | TraitTarget
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$version: "2"

namespace foo.baz

@suppress(["TraitTarget"])
@idempotent // < this is invalid
string MyString
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
$version: "2.0"

metadata suppressions = [
{
id: "ResourceOperationInputOutput",
namespace: "com.example"
}
]

namespace com.example

resource Resource1 {
Expand Down

0 comments on commit 764521f

Please sign in to comment.