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/branch.ml | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/branch.ml') diff --git a/lib/branch.ml b/lib/branch.ml index 8437d55..0b28663 100644 --- a/lib/branch.ml +++ b/lib/branch.ml @@ -3,6 +3,12 @@ bound to that branch. Each mutation names its target mg explicitly. *) module Make (NT : Nt.S) = struct + module Error = struct + open Condition + (* TODO: more structure *) + let not_supported msg = condition "not-supported" msg empty + let handle_error msg = condition "handle-error" msg empty + end let ( let* ) = Result.bind @@ -68,7 +74,7 @@ module Make (NT : Nt.S) = struct match mode with | Live -> Ok () | Detached _ -> - Error (Nt.NotSupported (op ^ ": detached snapshot is read-only")) + Error (Error.not_supported (op ^ ": detached snapshot is read-only")) method private sync_tip () = match mode with @@ -79,10 +85,10 @@ module Make (NT : Nt.S) = struct | Ok h -> tip <- h method private get_mg op (mg_name : string) : - (Management.Multigroup.multigroup, Nt.error) result = + (Management.Multigroup.multigroup, Condition.t) result = match Hashtbl.find_opt mgs mg_name with | Some mg -> Ok mg - | None -> Error (Nt.HandleError + | None -> Error (Error.handle_error (op ^ ": multigroup not found: " ^ mg_name)) method create_relation ~(mg : string) ~(rel_name : string) ~schema = @@ -104,7 +110,7 @@ module Make (NT : Nt.S) = struct let* () = self#assert_live "clear_relation" in let* mg_val = self#get_mg "clear_relation" mg in match mg_val#get_relation rel_name with - | None -> Error (Nt.HandleError ("relation not found: " ^ rel_name)) + | None -> Error (Error.handle_error ("relation not found: " ^ rel_name)) | Some rel -> let* (bh', mg') = NT.clear_relation bh mg_val -- cgit v1.2.3