Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,25 @@ public abstract class DynamicDispatchRpcCodec<T> implements RpcCodec<T> {
}
}

/**
* Verifies that at least one {@link DynamicDispatchRpcCodec} is registered for the
* given source file type. Call this at startup to fail fast when the ServiceLoader
* has not discovered the expected codec implementations (e.g. missing module on the
* classpath).
*
* @param sourceFileType The fully-qualified class name of the source file type
* (e.g. {@code "org.openrewrite.json.tree.Json$Document"}).
* @throws IllegalStateException if no codec is registered for the given type.
*/
public static void requireCodecFor(String sourceFileType) {
if (!CODEC_BY_TYPE.containsKey(sourceFileType)) {
throw new IllegalStateException(
"No DynamicDispatchRpcCodec registered for '" + sourceFileType + "'. " +
"The ServiceLoader found zero DynamicDispatchRpcCodec implementations for this type. " +
"Ensure that the module providing this codec is on the classpath.");
}
}

@SuppressWarnings("unchecked")
public static <T> @Nullable RpcCodec<T> getCodec(Object t, @Nullable String sourceFileType) {
if (sourceFileType == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
import org.openrewrite.javascript.JavaScriptParser;
import org.openrewrite.javascript.internal.rpc.JavaScriptValidator;
import org.openrewrite.javascript.tree.JS;
import org.openrewrite.json.tree.Json;
import org.openrewrite.marker.Markers;
import org.openrewrite.tree.ParseError;
import org.openrewrite.marketplace.RecipeBundleResolver;
import org.openrewrite.marketplace.RecipeMarketplace;
import org.openrewrite.rpc.DynamicDispatchRpcCodec;
import org.openrewrite.rpc.RewriteRpc;
import org.openrewrite.rpc.RewriteRpcProcess;
import org.openrewrite.rpc.RewriteRpcProcessManager;
Expand Down Expand Up @@ -344,6 +346,8 @@ public Builder workingDirectory(@Nullable Path workingDirectory) {

@Override
public JavaScriptRewriteRpc get() {
DynamicDispatchRpcCodec.requireCodecFor(Json.Document.class.getName());

Stream<@Nullable String> cmd;

if (inspectBrk != null) {
Expand Down