Fix smithyFormat classpath serialization error#161
Merged
Conversation
When smithyFormat fails on invalid syntax, the ModelSyntaxException thrown inside the isolated URLClassLoader cannot be serialized by Gradle's daemon (ShapeId is not visible to the daemon classloader). Strip the cause chain at the worker boundary and rethrow as a plain GradleException with only the root cause message.
JordonPhillips
approved these changes
Feb 19, 2026
| .buildAndFail(); | ||
|
|
||
| // The real error from the Smithy formatter must be present. | ||
| Assertions.assertTrue( |
Contributor
There was a problem hiding this comment.
Using assertThat with containsString from hamcrest will give better errors
Contributor
Author
There was a problem hiding this comment.
Yep, can do it as follow up.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Background
Root Cause
SmithyUtils.RunCliexecutes the Smithy CLI inside a customURLClassLoaderisolated from Gradle's daemon classloader. When the CLI throwsModelSyntaxException, the original catch block preserved the full cause chain viathrow new RuntimeException(e). Gradle's daemon serializer (ExceptionPlaceholder) then tries to introspect the exception's fields -- butModelSyntaxExceptionandShapeIdwere loaded by the isolated classloader, not the daemon's. Java class identity is per classloader instance, so the lookup fails even thoughsmithy-modelis already a plugin dependency.Fix
In
SmithyUtils.RunCli.execute(), unwrap the cause chain to the root, extract only the message string (falling back to the class name if the message is null), and throw a plainGradleExceptionwith no cause attached, so the daemon serializer never encounters the isolated types. Users still see the real error (e.g."Cannot format invalid models: Syntax error at line 105, column 8").An alternative is to add
smithy-modelto the daemon classpath.smithy-modelis already a plugin dependency, so it is present in the daemon's classpath. This still does not work as theModelSyntaxExceptioninstance was created by the isolatedURLClassLoader, and Java's class identity check requires the same classloader instance, not just the same JAR. Fixing this would require removing the classloader isolation entirely, which reintroducesZipException: invalid LOC headererrors from stale cached JARs that required us to isolate the Smithy CLI classloader in the first place.Testing
Added a regression test.
Links
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.