Helper for compiling expression and converting to proto. Simplifies error handling for brevity in the codelab.
| 30 | // |
| 31 | // Simplifies error handling for brevity in the codelab. |
| 32 | inline absl::StatusOr<cel::expr::CheckedExpr> CompileToCheckedExpr( |
| 33 | const cel::Compiler& compiler, absl::string_view expr) { |
| 34 | CEL_ASSIGN_OR_RETURN(cel::ValidationResult result, compiler.Compile(expr)); |
| 35 | |
| 36 | if (!result.IsValid() || result.GetAst() == nullptr) { |
| 37 | return absl::InvalidArgumentError(result.FormatError()); |
| 38 | } |
| 39 | |
| 40 | cel::expr::CheckedExpr pb; |
| 41 | CEL_RETURN_IF_ERROR(cel::AstToCheckedExpr(*result.GetAst(), &pb)); |
| 42 | return pb; |
| 43 | }; |
| 44 | |
| 45 | } // namespace cel_codelab |
| 46 |