Compilation and runtime errors from protovalidate are returned as Code.InvalidArgument
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
- Domain
- backend
Research direction
Start in packages/validate/src/interceptor.ts, where validate() returns early on kind === "valid" and then throws a single ConnectError for everything else; branch on result.kind === "error" and use Code.Internal there while leaving kind: "invalid" as Code.InvalidArgument. Look at the existing interceptor tests in packages/validate/src to mirror their setup, then add cases for a CEL compile error (field not found: c) and a runtime error (int divide by zero) using the descriptor/router pattern from the repro. Done means the repro prints 13 int divide by zero and the invalid-rule tests still report 3.
Written by the indexing model from the issue text.
Description
When validator.validate() returns kind: "error" (CompilationError or RuntimeError, such as a CEL expression that does not compile or hits int divide by zero), createValidateInterceptor() throws Code.InvalidArgument on requests instead of Code.Internal.
Reproduction (repro.mjs):
// npm i @connectrpc/[email protected] @bufbuild/[email protected] @bufbuild/[email protected] @connectrpc/[email protected]
// node repro.mjs
import { create, setExtension, createFileRegistry } from "@bufbuild/protobuf";
import { FileDescriptorProtoSchema, MessageOptionsSchema } from "@bufbuild/protobuf/wkt";
import { file_buf_validate_validate, message as messageRules, MessageRulesSchema } from "@bufbuild/protovalidate/gen/buf/validate/validate_pb.js";
import { createRouterTransport, createClient, ConnectError } from "@connectrpc/connect";
import { createValidateInterceptor } from "@connectrpc/validate";
// message Req {
// int64 a = 1;
// int64 b = 2;
// option (buf.validate.message).cel = { id: "div", expression: "this.a / this.b > 0" };
// }
const opts = create(MessageOptionsSchema);
setExtension(opts, messageRules, create(MessageRulesSchema, {
cel: [{ id: "div", expression: "this.a / this.b > 0" }],
}));
const reg = createFileRegistry(
create(FileDescriptorProtoSchema, {
name: "t.proto",
package: "t",
syntax: "proto3",
dependency: ["buf/validate/validate.proto"],
messageType: [
{
name: "Req",
options: opts,
field: [
{ name: "a", number: 1, type: 3, label: 1, jsonName: "a" },
{ name: "b", number: 2, type: 3, label: 1, jsonName: "b" },
],
},
{ name: "Res" },
],
service: [{ name: "S", method: [{ name: "Call", inputType: ".t.Req", outputType: ".t.Res" }] }],
}),
(n) => (n === "buf/validate/validate.proto" ? file_buf_validate_validate : undefined),
);
const S = reg.getService("t.S");
const transport = createRouterTransport(
({ service }) => service(S, { call: () => ({}) }),
{ router: { interceptors: [createValidateInterceptor()] } },
);
try {
await createClient(S, transport).call(create(reg.getMessage("t.Req"), { a: 4n, b: 0n }));
} catch (e) {
const err = ConnectError.from(e);
console.log(err.code, err.rawMessage);
}
Actual output:
3 int divide by zero
(3 is Code.InvalidArgument. A rule that fails to compile, such as this.c > 0, also returns 3 field not found: c on every request.)
Expected output: 13 int divide by zero (Code.Internal), reserving Code.InvalidArgument for kind: "invalid" rule violations, matching https://github.com/connectrpc/validate-go/pull/60.
In packages/validate/src/interceptor.ts, validate() checks if (result.kind === "valid") return; and throws new ConnectError(result.error.message, code, ...) for both kind: "invalid" and kind: "error".
Tested on @connectrpc/[email protected] (@bufbuild/[email protected], @bufbuild/[email protected], @connectrpc/[email protected], Node.js v26.13.0) and main (46aff93).
Credit: https://ucsbplse.github.io/
- Dominant language
- TypeScript
- Stars
- 14
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from connectrpc/validate-es
-
Difficulty 3/5 1-2 days Newbie friendliness 50/100
connectrpc/validate-es#53 ·
All issues in connectrpc/validate-es
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
Techiebutler/freeframe#687 ·
Maintainers usually reply within 1 day
-
enhancement from-app needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
nightly-labs/openbot#23050 ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
OHDSI/Data2Evidence#3846 ·
Maintainers usually reply within 3 days
-
frontend: EditorDialog: Save & Apply on an empty or comment-only document reports success and applies nothingPossibly taken @shubhamrai9122-creator claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
kubernetes-sigs/headlamp#9086 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
openai/openai-node#3232 ·
Maintainers usually reply within 1 day