Fix: CEL null results and readable cuex function-call errors

Merged
BR
1d ago
+62-14

Description of your changes

Two fixes ahead of KubeVela 1.12, one commit each.

1. Fix(cel): turn a null result into nil, not protobuf's NULL_VALUE

A $( ) expression whose result is null reached the properties document as protobuf's
NULL_VALUE rather than as a null. native() fell through to cel-go's Null.Value(), which is
structpb.NullValue_NULL_VALUE, so a whole-value read such as replicas: "$(source.x.maybe)"
was marshalled as 0, and a read inside text, such as "host-$(source.x.maybe)", became the
text host-NULL_VALUE.

A null now converts to nil, at any depth: a whole value stays null, and a null inside a list or
a map stays null there. Text refuses to embed one, as it already refuses a list or a map, with a
hint to guard the read:

"source.x.maybe" is null, which text cannot embed; guard it, for example has(x) && x != null ? x : "none"

Every CEL result reaches Go data through Engine.run, so the change covers Eval,
EvalProperty and Plan.Eval alike.

Downstream: kubevela (pkg/definition/celexpr, pkg/sources) and workflow (pkg/expressions)
have no expectations on NULL_VALUE or on a null reading as 0. A null step if in workflow
now reads "is null, but a step's if must be a bool", rather than naming the protobuf type.

Tested:

  • TestEvalNull (red before the change: got 0, <nil>; want nil): a null field, a whole-value
    $(null), a list holding a null, and a null embedded in text.
  • go test ./... and golangci-lint.
  • A kubevela controller built against this branch: a whole-value null renders as null, a null
    in text fails the render with the message above, and a guarded read renders its fallback.

2. Fix(cuex): keep a provider call's value out of its error message

A failed provider call's error ended with the whole call: (value: #do: "do" #provider: "http" $params: {...} #config: {...} $returns: {...}). The message is what reaches an Application's
status, as a workflow step's message and a source binding's resolution message, so a connection
refused became twenty lines of CUE. KubeVela's admission webhook already strips the value back out to
keep its own errors readable.

The message now names the call and what the provider reported. Value stays on
FunctionCallError for a caller that wants the call as made.

Tested: cue/cuex error tests updated to the new message, red on the old one.

How has this code been tested

  • go test ./... with envtest 1.37.0, on the combined branch.
  • make reviewable, clean.

Special notes for your reviewer

Neither change is released: $( ) property expressions and source bindings arrived after the last
tag. KubeVela picks both up on its next pin of kubevela/pkg. Once it pins this, its admission
webhook no longer needs to strip the value from provider-call errors (conciseSchematicError).


Summary by cubic

Fixes CEL null handling and unreadable provider-call errors ahead of KubeVela 1.12.

Bug Fixes

  • A $( ) expression whose result is null now converts to nil at any depth — including inside lists and maps — instead of protobuf's NULL_VALUE, so a whole-value null stays null instead of marshalling as 0, and text refuses to embed a null with a hint to guard the read.
  • A failed provider call's error no longer embeds the whole call value, so connection failures show as a readable one-line message in Application status; the value stays available on FunctionCallError.Value.