From 9dc0391443ca16bf1ab3114d002aad83872f8a73 Mon Sep 17 00:00:00 2001 From: Estevan Castilho Date: Wed, 27 May 2026 23:24:12 +0000 Subject: Improve the error handling situation (#71) * Sketches of a condition system * `Condition.condition` -> `Condition.t` * Migrate `NT` over * Migrate `Branch` over * Migrate `Sublanguage` et al. over * Migrate the PRL over * Migrate the DRL over * Migrate the DML over * Have `Qualified_name.try_parse` return a `Condition.t` * Migrate the DDL over * Migrate the VCL over * Migrate the SCL over * Migrate the ICL over * Migrate the parsers over * Just inherit the errors from NT and the sublanguages * Migrate `Management.Physical` over * Migrate `Configuration` over * Migrate `Management.Branch` over * Migrate `Transport` over * Migrate `System` over * Migrate `Server` over * Include messages on on all conditions * A prettier stringifier --- lib/icl/executor.ml | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) (limited to 'lib/icl/executor.ml') diff --git a/lib/icl/executor.ml b/lib/icl/executor.ml index 0a77dff..084fb71 100644 --- a/lib/icl/executor.ml +++ b/lib/icl/executor.ml @@ -1,31 +1,19 @@ module Make (NT : Nt.S) = struct - type error = - | ParseError of string - | NtError of Nt.error - | ConversionError of string - | MultigroupNotFound of string - | UnqualifiedName of string - - let sexp_of_error e = - let open Sexplib.Sexp in - match e with - | ParseError s -> List [ Atom "parse-error"; Atom s ] - | NtError e -> List [ Atom "nt-error"; Atom (Nt.string_of_error e) ] - | ConversionError s -> List [ Atom "conversion-error"; Atom s ] - | MultigroupNotFound s -> List [ Atom "multigroup-not-found"; Atom s ] - | UnqualifiedName s -> List [ Atom "unqualified-name"; Atom s ] + module Error = struct + open Condition + let multigroup_not_found name = condition "multigroup-not-found" "Multigroup not found" ("name" |=| (of_string name)) + end let ( let* ) = Result.bind - let wrap_nt = Result.map_error (fun e -> NtError e) - let parse_fqn (s : string) : (Qualified_name.t, error) result = - Qualified_name.try_parse s |> Result.map_error (fun s -> UnqualifiedName s) + let parse_fqn (s : string) : (Qualified_name.t, Condition.t) result = + Qualified_name.try_parse s let lookup_mg (ctx : Sublanguage_context.t) (mg_name : string) : - (Management.Multigroup.multigroup, error) result = + (Management.Multigroup.multigroup, Condition.t) result = match ctx.branch#mg_of mg_name with | Some mg -> Ok mg - | None -> Error (MultigroupNotFound mg_name) + | None -> Error (Error.multigroup_not_found mg_name) let convert_binding_expr : Ast.binding_expr -> Constraint.binding_expr = function @@ -52,7 +40,7 @@ module Make (NT : Nt.S) = struct Constraint.forall ~variable ~quantifier (convert_body body) let execute (ctx : Sublanguage_context.t) (stmt : Ast.statement) : - (Sublanguage_types.transition_delta * string, error) result = + (Sublanguage_types.transition_delta * string, Condition.t) result = match stmt with | Ast.RegisterConstraint { constraint_name; relation_name; body } -> let* fqn = parse_fqn relation_name in @@ -61,7 +49,6 @@ module Make (NT : Nt.S) = struct let* _bh, new_mg = NT.register_constraint ctx.write_handle mg ~constraint_name ~relation_name:fqn.name ~body:runtime_body - |> wrap_nt in ctx.branch#set_mg ~name:fqn.mg new_mg; Ok ([ (fqn.mg, new_mg) ], "Constraint registered: " ^ constraint_name) -- cgit v1.2.3