-
Notifications
You must be signed in to change notification settings - Fork 22
Fix smithyFormat classpath serialization error #161
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
examples/base-plugin/failure-cases/syntax-error-format/build.gradle.kts
This file contains hidden or 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,14 @@ | ||
| // This example fails because smithyFormat is run on a model with a syntax error. | ||
| // format is intentionally left enabled (the default) to exercise the smithyFormat task path. | ||
| // the build must fail with the real syntax error message, not a secondary NoClassDefFoundError | ||
| // caused by smithy-model types escaping the isolated classloader. | ||
|
|
||
| plugins { | ||
| id("java-library") | ||
| id("software.amazon.smithy.gradle.smithy-base").version("1.3.0") | ||
| } | ||
|
|
||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } |
7 changes: 7 additions & 0 deletions
7
examples/base-plugin/failure-cases/syntax-error-format/model/main.smithy
This file contains hidden or 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,7 @@ | ||
| namespace smithy.example | ||
|
|
||
| // Intentional syntax error: bare keyword with no identifier following it. | ||
| // The smithyFormat task must fail with a clear "Cannot format invalid models" message, | ||
| // not a secondary NoClassDefFoundError (regression for SMITHY-3541). | ||
| structure | ||
|
|
8 changes: 8 additions & 0 deletions
8
examples/base-plugin/failure-cases/syntax-error-format/settings.gradle.kts
This file contains hidden or 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,8 @@ | ||
| rootProject.name = "syntax-error-format" | ||
|
|
||
| pluginManagement { | ||
| repositories { | ||
| mavenLocal() | ||
| mavenCentral() | ||
| } | ||
| } |
3 changes: 3 additions & 0 deletions
3
examples/base-plugin/failure-cases/syntax-error-format/smithy-build.json
This file contains hidden or 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,3 @@ | ||
| { | ||
| "version": "1.0" | ||
| } |
45 changes: 45 additions & 0 deletions
45
smithy-base/src/it/java/software/amazon/smithy/gradle/SyntaxErrorFormatTest.java
This file contains hidden or 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,45 @@ | ||
| /* | ||
| * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package software.amazon.smithy.gradle; | ||
|
|
||
| import org.gradle.testkit.runner.BuildResult; | ||
| import org.gradle.testkit.runner.GradleRunner; | ||
| import org.gradle.testkit.runner.TaskOutcome; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * Regression test for case when smithyFormat runs on a model with a syntax error, | ||
| * the build must fail with the real "Cannot format invalid models" message rather than a | ||
| * secondary NoClassDefFoundError caused by smithy-model types (e.g. ShapeId) escaping the | ||
| * isolated URLClassLoader and failing Gradle's daemon exception serializer. | ||
| */ | ||
| public class SyntaxErrorFormatTest { | ||
| @Test | ||
| public void formatTaskFailsWithReadableMessageOnSyntaxError() { | ||
| Utils.withCopy("base-plugin/failure-cases/syntax-error-format", buildDir -> { | ||
| BuildResult result = GradleRunner.create() | ||
| .forwardOutput() | ||
| .withProjectDir(buildDir) | ||
| .withArguments("smithyFormat", "--stacktrace") | ||
| .buildAndFail(); | ||
|
|
||
| // The real error from the Smithy formatter must be present. | ||
| Assertions.assertTrue( | ||
| result.getOutput().contains("Cannot format invalid models"), | ||
| "Expected 'Cannot format invalid models' in :smithyFormat output but got:\n" + result.getOutput()); | ||
|
|
||
| // A NoClassDefFoundError for ShapeId would indicate the classloader isolation bug has regressed. | ||
| Assertions.assertFalse( | ||
| result.getOutput().contains("NoClassDefFoundError"), | ||
| "Unexpected NoClassDefFoundError in output -- classloader isolation regression:\n" | ||
| + result.getOutput()); | ||
|
|
||
| // The smithyFormat task itself must be the one that failed, not some other task. | ||
| Assertions.assertEquals(TaskOutcome.FAILED, result.task(":smithyFormat").getOutcome()); | ||
| }); | ||
| } | ||
| } | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using assertThat with containsString from hamcrest will give better errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, can do it as follow up.