{"record":{"id":"ca34df36bc499bcc","repo":"quarkusio/quarkus","slug":"runtimeexception-e-ca34df","errorCode":null,"errorMessage":"RuntimeException(e)","messagePattern":"RuntimeException\\(e\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"extensions/grpc/cli/src/main/java/io/quarkus/grpc/cli/InvokeCommand.java","lineNumber":78,"sourceCode":"                            });\n                }\n            } else {\n                err(\"Unexpected response from server reflection: \" + responseCase);\n            }\n            return null;\n        }).await().indefinitely();\n    }\n\n    private void invokeMethod(Descriptors.MethodDescriptor md) {\n        String fullMethodName = md.getService().getFullName() + \"/\" + md.getName();\n        Descriptors.Descriptor inputType = md.getInputType();\n        DynamicMessage.Builder messageBuilder = DynamicMessage.newBuilder(inputType);\n        try {\n            content.ifPresent(request -> {\n                try {\n                    JsonFormat.parser().merge(request, messageBuilder);\n                } catch (InvalidProtocolBufferException e) {\n                    throw new RuntimeException(e);\n                }\n            });\n            DynamicMessage msg = messageBuilder.build();\n            MethodDescriptor.MethodType methodType = MethodDescriptor.MethodType.UNARY;\n            if (md.isClientStreaming()) {\n                methodType = MethodDescriptor.MethodType.CLIENT_STREAMING;\n            }\n            if (md.isServerStreaming()) {\n                methodType = MethodDescriptor.MethodType.SERVER_STREAMING;\n            }\n            if (md.isClientStreaming() && md.isServerStreaming()) {\n                methodType = MethodDescriptor.MethodType.BIDI_STREAMING;\n            }\n            MethodDescriptor<DynamicMessage, DynamicMessage> methodDescriptor = io.grpc.MethodDescriptor\n                    .<DynamicMessage, DynamicMessage> newBuilder()\n                    .setType(methodType)\n                    .setFullMethodName(fullMethodName)\n                    .setRequestMarshaller(ProtoUtils.marshaller(DynamicMessage.getDefaultInstance(inputType)))","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/quarkusio/quarkus/blob/e1c734241f34c7919086ceb4c9262b4a58f6de44/extensions/grpc/cli/src/main/java/io/quarkus/grpc/cli/InvokeCommand.java#L60-L96","documentation":"InvokeCommand builds the request message from JSON using JsonFormat.parser().merge into a DynamicMessage. If the supplied JSON does not conform to the proto (bad types, unknown fields, malformed JSON), InvalidProtocolBufferException is wrapped in RuntimeException and thrown, aborting the invocation.","triggerScenarios":"`quarkus grpc invoke` where the --request/-j JSON string mismatches the method's input type: wrong field names, string given for number, invalid base64 for bytes, malformed JSON syntax.","commonSituations":"Copy-pasting JSON shaped for a REST API instead of the proto message; camelCase vs snake_case field naming mistakes; passing JSON for the wrong method after refactoring.","solutions":["Validate the JSON against the proto message definition (check field names/types via `quarkus grpc describe`)","Use correct protobuf JSON conventions: camelCase names, base64 for bytes, strings for int64","Escape the JSON properly on the shell (single quotes) so it reaches the parser intact"],"exampleFix":"// before\nString req = \"{user_id: 42}\"; // proto syntax, not JSON\ncli.invokeMethod(..., Optional.of(req), ...); // RuntimeException\n// after\nString req = \"{\\\"userId\\\": 42}\"; // valid protobuf JSON\ncli.invokeMethod(..., Optional.of(req), ...);","handlingStrategy":"validation","validationCode":"// Validate JSON parses and matches proto JSON rules before invoking:\ntry {\n    new com.fasterxml.jackson.databind.ObjectMapper().readTree(requestJson);\n} catch (Exception e) {\n    throw new IllegalArgumentException(\"Request JSON is malformed: \" + e.getMessage());\n}\n// then check field names against `quarkus grpc describe MyService` output","typeGuard":"boolean isValidJson(String s) {\n    try { new ObjectMapper().readTree(s); return true; }\n    catch (Exception e) { return false; }\n}","tryCatchPattern":"try {\n    command.invokeMethod(...);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof InvalidProtocolBufferException ipbe) {\n        System.err.println(\"JSON does not match proto: \" + ipbe.getMessage());\n    }\n}","preventionTips":["Generate request JSON from the describe output instead of hand-writing it","Use protobuf JSON conventions: camelCase field names, base64 bytes, ISO strings for timestamps","Quote JSON correctly in the shell (single quotes) to avoid mangling"],"tags":["grpc","cli","json-parsing"],"backgroundTag":"invalid-json-in-request","analyzedSha":"e1c734241f34c7919086ceb4c9262b4a58f6de44","analyzedAt":"2026-09-05T17:01:29.979Z","contentChangedAt":"2026-09-05T17:01:29.979Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}