-
Notifications
You must be signed in to change notification settings - Fork 28.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SPARK-49538][SQL][TESTS] Detect unused error message parameters
### What changes were proposed in this pull request? In the PR, I propose to detect unused error message parameters while substituting placeholders in error message formats, and raise an internal error in tests when the number of parameters is greater than the number of placeholders. That might indicate presence of unused message parameters. ### Why are the changes needed? Might happens that the passed error message parameters and placeholders in message format are not matched, and contain extra items. From the code maintainability perspective, it would be nice to detect such cases while running tests. For example, the error message format could look like: ```json "CANNOT_UP_CAST_DATATYPE" : { "message" : [ "Cannot up cast <expression> from <sourceType> to <targetType>.", "<details>" ], "sqlState" : "42846" }, ``` but the passed message parameters have extra parameter: ```scala messageParameters = Map( "expression" -> "CAST('aaa' AS LONG)", "sourceType" -> "STRING", "targetType" -> "LONG", "op" -> "CAST", // unused parameter "details" -> "implicit cast" )) ``` This can happen because: - tech editor/dev forgot to mention some parameters in error message format, - wrong usage of error conditions/sub-conditions - source code became outdated - typos in error message formats ### Does this PR introduce _any_ user-facing change? No. ### How was this patch tested? By running the added test via: ``` $ build/mvn -Dtest=none -DwildcardSuites=org.apache.spark.SparkThrowableSuite test ``` ### Was this patch authored or co-authored using generative AI tooling? No. Closes #48026 from MaxGekk/detect-unused-error-params. Authored-by: Max Gekk <[email protected]> Signed-off-by: Max Gekk <[email protected]>
- Loading branch information
Showing
5 changed files
with
41 additions
and
24 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
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