using custom pb type for expression error

6 views
Skip to first unread message

mohit nagpal

unread,
Jul 21, 2024, 3:12:21 PM (6 days ago) Jul 21
to CEL Go Discussion Forum
trying below for custome pb type for expression does not work
with env creation error: unsupported type: *gatewaypb.NoteRequest

import gatewaypb "gogoproto/xxxxx"

req := gatewaypb.NoteRequest{
Note: &gatewaypb.Note{
Note: &google_protobuf2.StringValue{Value: "noteval"},
},
}

// Step 2: Set up the go-cel environment
env, err := cel.NewEnv(
cel.Types(&gatewaypb.NoteRequest{}, &gatewaypb.Note{}),
cel.Declarations(
decls.NewVar("req", decls.NewObjectType("gatewaypb.NoteRequest")),
),
)
if err != nil {
fmt.Println("env creation error:", err)
return
}

// Step 3: Create and evaluate a go-cel expression
ast, iss := env.Compile(`req.Note.Note.Value == "noteval"`)
if iss.Err() != nil {
fmt.Println("compile error:", iss.Err())
return
}

prg, err := env.Program(ast)
if err != nil {
fmt.Println("program creation error:", err)
return
}

// Evaluate the expression
out, _, err := prg.Eval(map[string]interface{}{
"req": req,
})
if err != nil {
fmt.Println("evaluation error:", err)
return
}

fmt.Println("Evaluation result:", out)

Tristan Swadell

unread,
Jul 22, 2024, 11:40:47 AM (5 days ago) Jul 22
to mohit nagpal, CEL Go Discussion Forum
Hi Mohit,

Could you provide the error message you're getting? My guess is that `.Value` is getting flagged as not defined since google.protobuf.StringValue is treated like a nullable string rather than a proto object.

-Tristan

--
You received this message because you are subscribed to the Google Groups "CEL Go Discussion Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cel-go-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/cel-go-discuss/5c219bdb-c437-4dc0-929d-69b7b6d9c490n%40googlegroups.com.

mohit nagpal

unread,
Jul 23, 2024, 6:59:18 PM (4 days ago) Jul 23
to Tristan Swadell, CEL Go Discussion Forum
Error is : 

env creation error:unsupported type: *gatewaypb.AddUserNoteRequest

Thanks,
Mohit Nagpal


 

Tristan Swadell

unread,
Jul 25, 2024, 11:56:18 AM (2 days ago) Jul 25
to mohit nagpal, CEL Go Discussion Forum
Hi Mohit,

The error message and the test setup don't appear to be quite the same. The type referenced is a gatewaypb.AddUserNoteRequest, but I don't see this declared to CEL. It's also possible that this is a difference between how protobuf-golang handles types and gogoproto does. I think we've seen some compatibility issues in the past with gogoproto, so I'd recommend trying protobuf golang instead.

-Tristan

On Wed, Jul 24, 2024 at 8:51 PM mohit nagpal <mht.n...@gmail.com> wrote:
any clue why type is not getting registered or anything missing in registration.

Thanks,
Mohit Nagpal


 

Reply all
Reply to author
Forward
0 new messages