[BUG] A CEL rule naming a missing field is a RuntimeError, not a CompilationError

Aperta
#222 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
52/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
compilers

Direzione di ricerca

Start by reading check in packages/cel/src/check.ts to see the type-checking API it expects, then CelManager.compileRule in packages/protovalidate/src/cel.ts where plan(this.env, parse(rule.expression)) runs untyped. Export check from packages/cel/src/index.ts, call it before planning with this (and rules/rule for predefined rules) declared, then run the custom_rules conformance suite and drop compilation/missing_field and compilation/incorrect_type from packages/protovalidate-testing/expected-failures.yaml. Done means the missing-field rule surfaces a CompilationError at type load instead of a per-call RuntimeError.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Description

A CEL rule that names a field the message doesn't have compiles, and every validation of the type then fails with a RuntimeError. The conformance case custom_rules compilation/missing_field expects a CompilationError, and packages/protovalidate-testing/expected-failures.yaml lists it (with compilation/incorrect_type) as an expected failure under --strict_error.

CelManager.compileRule (packages/protovalidate/src/cel.ts) builds the rule with plan(this.env, parse(rule.expression)), so nothing type-checks it. @bufbuild/cel already has a checker (check in packages/cel/src/check.ts), but packages/cel/src/index.ts doesn't export it.

Steps to Reproduce

message BrokenRequest {
  option (buf.validate.message).cel = {
    id: "broken"
    expression: "this.missing == 1"
  };
  string name = 1;
}
import { create } from "@bufbuild/protobuf";
import { createValidator } from "@bufbuild/protovalidate";
import { BrokenRequestSchema } from "./gen/rules_pb.js";

const result = createValidator().validate(BrokenRequestSchema, create(BrokenRequestSchema, { name: "x" }));
console.log(result.kind, String(result.error));

Expected Behavior

error CompilationError: ..., as protovalidate-go reports when the type is first loaded.

Actual Behavior

error RuntimeError: field not found: missing, on every call.

Environment

  • @bufbuild/protovalidate version: 1.3.0 (main has the same compileRule)
  • @bufbuild/cel version: 0.6.1
  • @bufbuild/cel-spec version: 0.6.1
  • Node.js version: v26.13.1
  • Protobuf Compiler & Version: protoc-gen-es 2.17.0

Possible Solution

Export check from @bufbuild/cel and run it in compileRule with this (and rules/rule for predefined rules) declared as the message or rule type. A selection of a missing field, or a call with the wrong argument types, then fails at compile time, and compilation/missing_field and compilation/incorrect_type could leave the expected failures.

Additional Context

A typo in a rule is a schema error, but as a RuntimeError it looks the same as a failure that depends on the message's values, such as a division by a field that is zero. A caller that wants to refuse a broken schema at startup, for example by validating each request type once when a client is created, can't tell the two apart without matching error text. So a client with a typo in a rule is created without complaint and then fails every request of that type.

Lingua principale
TypeScript
Stelle
85
Fork
14
Merge medio
2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di bufbuild/protovalidate-es

Tutte le issue di bufbuild/protovalidate-es

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.