-
Notifications
You must be signed in to change notification settings - Fork 220
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Selector attributes are curretly *too* permissive, and this makes it harr to know when a selector is invalid. The original intent of making selector attributes permissive was to make it possible to add new attributes and nested attribute values without needing to version the Smithy specification, but this looseness ended up making it really hard to understand if you were using the current version of the specification correctly. For example, consider the following selector that previously worked: ``` [id|com.foo#Baz] ``` Smithy previoulsy would let this through, and it didn't emit any warnings. This should have been: ``` [id=com.foo#Baz] ``` It's in our users' best interest for us to be stricer about attributes so that they know when they use them incorrectly. Even as the designer of selectors, I got this wrong, and struggled for about 20 minutes trying to figure out why. This change no longer allows wildcard access to top level shapes, the id attribute, or the service attribute. While this _is_ a breaking change, it's a desirable breaking change that will only serve to reveal bugs in selectors. The following selecors are examples that will no longer work: * `[id|com.foo#Baz]` (invalid wildcard access of id) * `[foo]` (invalid top-level attribute) * `[id|foo]` (invalid wildcard access of id) * `[service|foo]` (invalid wildcard access of service) * `[service|id|foo]` (invalid wildcard access of id) Attempting to access traits that do not exist, variables that do not exist, values of traits or variables that do not exist, or to descend into literal scalar values will continue to work and will continue to return an empty value: * `[id|name|foo]` (descending into scalars is still ok. This might be a legitimate use case when using heterogenous projections, for example). * `[vars|doesNotExist|nested]` (accessing unknown variables is ok) * `[service|id|name|foo]` (descending into scalars is ok, even nested) * `[trait|doesNotExist]` (accessing wildcard traits, even unknown traits is ok).
- Loading branch information
Showing
6 changed files
with
75 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
smithy-model/src/main/java/software/amazon/smithy/model/selector/SelectorException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2021 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://aws.amazon.com/apache2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file is distributed | ||
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either | ||
* express or implied. See the License for the specific language governing | ||
* permissions and limitations under the License. | ||
*/ | ||
|
||
package software.amazon.smithy.model.selector; | ||
|
||
/** | ||
* Exception thrown when a selector evaluation is invalid. | ||
*/ | ||
public class SelectorException extends RuntimeException { | ||
public SelectorException(String message) { | ||
super(message); | ||
} | ||
|
||
public SelectorException(String message, Throwable previous) { | ||
super(message, previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters