File tree Expand file tree Collapse file tree
rewrite-core/src/main/java/org/openrewrite/rpc
rewrite-javascript/src/main/java/org/openrewrite/javascript/rpc Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -37,6 +37,25 @@ public abstract class DynamicDispatchRpcCodec<T> implements RpcCodec<T> {
3737 }
3838 }
3939
40+ /**
41+ * Verifies that at least one {@link DynamicDispatchRpcCodec} is registered for the
42+ * given source file type. Call this at startup to fail fast when the ServiceLoader
43+ * has not discovered the expected codec implementations (e.g. missing module on the
44+ * classpath).
45+ *
46+ * @param sourceFileType The fully-qualified class name of the source file type
47+ * (e.g. {@code "org.openrewrite.json.tree.Json$Document"}).
48+ * @throws IllegalStateException if no codec is registered for the given type.
49+ */
50+ public static void requireCodecFor (String sourceFileType ) {
51+ if (!CODEC_BY_TYPE .containsKey (sourceFileType )) {
52+ throw new IllegalStateException (
53+ "No DynamicDispatchRpcCodec registered for '" + sourceFileType + "'. " +
54+ "The ServiceLoader found zero DynamicDispatchRpcCodec implementations for this type. " +
55+ "Ensure that the module providing this codec is on the classpath." );
56+ }
57+ }
58+
4059 @ SuppressWarnings ("unchecked" )
4160 public static <T > @ Nullable RpcCodec <T > getCodec (Object t , @ Nullable String sourceFileType ) {
4261 if (sourceFileType == null ) {
Original file line number Diff line number Diff line change 2323import org .openrewrite .javascript .JavaScriptParser ;
2424import org .openrewrite .javascript .internal .rpc .JavaScriptValidator ;
2525import org .openrewrite .javascript .tree .JS ;
26+ import org .openrewrite .json .tree .Json ;
2627import org .openrewrite .marker .Markers ;
2728import org .openrewrite .tree .ParseError ;
2829import org .openrewrite .marketplace .RecipeBundleResolver ;
2930import org .openrewrite .marketplace .RecipeMarketplace ;
31+ import org .openrewrite .rpc .DynamicDispatchRpcCodec ;
3032import org .openrewrite .rpc .RewriteRpc ;
3133import org .openrewrite .rpc .RewriteRpcProcess ;
3234import org .openrewrite .rpc .RewriteRpcProcessManager ;
@@ -344,6 +346,8 @@ public Builder workingDirectory(@Nullable Path workingDirectory) {
344346
345347 @ Override
346348 public JavaScriptRewriteRpc get () {
349+ DynamicDispatchRpcCodec .requireCodecFor (Json .Document .class .getName ());
350+
347351 Stream <@ Nullable String > cmd ;
348352
349353 if (inspectBrk != null ) {
You can’t perform that action at this time.
0 commit comments