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

Add service id to the error message to aid debugging #2483

Conversation

sugmanue
Copy link
Contributor

@sugmanue sugmanue commented Dec 6, 2024

Background

When a resource is in the closure of more than one service the TaggableResource error won't say for which one it failed, e.g.,

[ERROR] example.weather#City: Resource does not have tagging CRUD operations and is not compatible with service-wide tagging operations. | TaggableResource 

This change add the service to better understand where the issue is.

[ERROR] example.weather#City: Resource does not have tagging CRUD operations and is not compatible with service-wide tagging operations for service `example.weather#Weather`.

While there I also made minor changes to improve the code around.

Testing

  • Added tests for this case

Links

  • Links to additional context, if necessary
  • Issue #, if applicable (see here for a list of keywords to use for linking issues)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@sugmanue sugmanue requested a review from a team as a code owner December 6, 2024 04:02
@sugmanue sugmanue requested a review from milesziemer December 6, 2024 04:02
TopDownIndex topDownIndex = TopDownIndex.of(model);
AwsTagIndex tagIndex = AwsTagIndex.of(model);
for (ServiceShape service : model.getServiceShapes()) {
for (ResourceShape resource : topDownIndex.getContainedResources(service)) {
boolean resourceLikelyTaggable = false;
if (resource.hasTrait(TaggableTrait.class)) {
if (resource.hasTrait(TaggableTrait.class) && service.getResources().contains(resource.getId())) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't right. It's only checking resource shapes bound directly to the service, meaning this won't run on nested resources (service -> parent -> child - child won't be checked.)

TopDownIndex topDownIndex = TopDownIndex.of(model);
AwsTagIndex tagIndex = AwsTagIndex.of(model);
for (ServiceShape service : model.getServiceShapes()) {
for (ResourceShape resource : topDownIndex.getContainedResources(service)) {
boolean resourceLikelyTaggable = false;
if (resource.hasTrait(TaggableTrait.class)) {
if (resource.hasTrait(TaggableTrait.class) && service.getResources().contains(resource.getId())) {
events.addAll(validateResource(model, resource, service, tagIndex));
Copy link
Contributor

@kstich kstich Dec 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error messages in validateResource that are related to the service's tagging operations should include the ID of the service shape to aid in debugging.

@kstich kstich requested review from kstich and removed request for milesziemer December 6, 2024 06:06
@sugmanue sugmanue force-pushed the sugmanue/exclude-non-bound-resources-from-validation branch from 0bf70f9 to 483d36b Compare December 6, 2024 20:49
@sugmanue sugmanue changed the title Run the taggable resource validator only on resources bound to the service Add service id to the error message to aid debugging Dec 6, 2024
@sugmanue sugmanue force-pushed the sugmanue/exclude-non-bound-resources-from-validation branch from 483d36b to a496f79 Compare December 6, 2024 21:16
@@ -87,7 +87,6 @@ private List<ValidationEvent> validateResource(
// list or tag keys input or output member
// 2. Tagging via APIs specified in the @taggable trait which are validated
// through the tag property, and must be resource instance operations
//Caution: avoid short circuiting behavior.
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is misleading, you only want to avoid short circuiting if you are expecting a side effect, that's not the case here.

if (!(isServiceWideTaggable || isInstanceOpTaggable)) {
events.add(error(resource, "Resource does not have tagging CRUD operations and is not compatible"
+ " with service-wide tagging operations."));
if (!isServiceWideTaggable && !isInstanceOpTaggable) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition written this way expresses more clearly what we want.

Optional<String> property = resource.expectTrait(TaggableTrait.class).getProperty();
if (property.isPresent()) {
if (operationId.isPresent()) {
if (operationId.isPresent()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only way for this code to branch to true is for when the optional operationId is present. I moved it up to avoid unneeded work when that's not true.

@sugmanue sugmanue merged commit f8ac947 into smithy-lang:main Dec 6, 2024
13 checks passed
@sugmanue sugmanue deleted the sugmanue/exclude-non-bound-resources-from-validation branch December 6, 2024 21:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants