diff options
| author | Estevan Castilho <tevo@riajuu.net> | 2026-05-27 23:24:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-27 23:24:12 +0000 |
| commit | 9dc0391443ca16bf1ab3114d002aad83872f8a73 (patch) | |
| tree | e4f78a2533e5e633b733c1ea21d0159aeca79b75 /lib/prl | |
| parent | f9097a0562ea8b40d40a19059578a9280b945de4 (diff) | |
| download | Sakura-9dc0391443ca16bf1ab3114d002aad83872f8a73.tar.gz Sakura-9dc0391443ca16bf1ab3114d002aad83872f8a73.zip | |
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
Diffstat (limited to '')
| -rw-r--r-- | lib/prl/executor.ml | 34 | ||||
| -rw-r--r-- | lib/prl/parser.ml | 7 | ||||
| -rw-r--r-- | lib/prl/sublanguage.ml | 7 |
3 files changed, 19 insertions, 29 deletions
diff --git a/lib/prl/executor.ml b/lib/prl/executor.ml index 0ccaf22..fcd4ec0 100644 --- a/lib/prl/executor.ml +++ b/lib/prl/executor.ml @@ -1,22 +1,14 @@ module Make (NT : Nt.S) = struct - type error = - | ParseError of string - | RuntimeError of string - | NtError of Nt.error - | UnknownPluginSymbol of string - | RelationNotFound of string - - let sexp_of_error e = - let open Sexplib.Sexp in - match e with - | ParseError s -> List [ Atom "parse-error"; Atom s ] - | RuntimeError s -> List [ Atom "runtime-error"; Atom s ] - | NtError e -> List [ Atom "nt-error"; Atom (Nt.string_of_error e) ] - | UnknownPluginSymbol s -> List [ Atom "unknown-plugin-symbol"; Atom s ] - | RelationNotFound s -> List [ Atom "relation-not-found"; Atom s ] + module Error = struct + open Condition + (* TODO: more structure *) + let parse_error msg = condition "parse-error" msg empty + let runtime_error msg = condition "runtime-error" msg empty + let unknown_plugin_symbol name = condition "unknown-plugin-symbol" "Unknown plugin" ("name" |=| (of_string name)) + let relation_not_found name = condition "relation-not-found" "Relation not found" ("name" |=| (of_string name)) + end let ( let* ) = Result.bind - let _map_nt r = Result.map_error (fun e -> NtError e) r (* TODO: PRL function predicates are OCaml shared-library callbacks that produce tuples at runtime. To make their output joinable inside the @@ -26,17 +18,17 @@ module Make (NT : Nt.S) = struct yet exist. Disable PRL execution until that bridge is in place. *) let execute (_ctx : Sublanguage_context.t) (_stmt : Ast.statement) : - (Sublanguage_types.result, error) result = - Error (RuntimeError + (Sublanguage_types.result, Condition.t) result = + Error (Error.runtime_error "PRL execution is temporarily disabled pending VM callback-cursor support") let _execute_load_library _ctx _path = - Error (RuntimeError "PRL disabled") + Error (Error.runtime_error "PRL disabled") let _execute_define_function_predicate _ctx (_spec : Ast.function_predicate) = let* _ = Ok () in - Error (RuntimeError "PRL disabled") + Error (Error.runtime_error "PRL disabled") let _execute_list_function_predicates _ctx = - Error (RuntimeError "PRL disabled") + Error (Error.runtime_error "PRL disabled") end diff --git a/lib/prl/parser.ml b/lib/prl/parser.ml index 17102a4..2567eea 100644 --- a/lib/prl/parser.ml +++ b/lib/prl/parser.ml @@ -1,4 +1,7 @@ -type error = ParseError of string +module Error = struct + open Condition + let parse_error msg = condition "parse-error" msg empty +end let of_sexp sexp = let sexp = @@ -6,7 +9,7 @@ let of_sexp sexp = in match Ast.statement_of_sexp sexp with | stmt -> Ok stmt - | exception exn -> Error (ParseError (Printexc.to_string exn)) + | exception exn -> Error (Error.parse_error (Printexc.to_string exn)) let of_string s = of_sexp (Sexplib.Sexp.of_string s) let to_string stmt = Ast.sexp_of_statement stmt |> Sexplib.Sexp.to_string_hum diff --git a/lib/prl/sublanguage.ml b/lib/prl/sublanguage.ml index 96891a9..387da34 100644 --- a/lib/prl/sublanguage.ml +++ b/lib/prl/sublanguage.ml @@ -3,16 +3,11 @@ module Make (NT : Nt.S) = struct type configuration = unit type ast = Ast.statement - type error = Exec.error let name = "prl" let parse _ = Ok () - let parse_sexp sexp = - match Parser.of_sexp sexp with - | Ok r -> Ok r - | Error (Parser.ParseError s) -> Error (Exec.ParseError s) + let parse_sexp sexp = Parser.of_sexp sexp let execute = Exec.execute - let sexp_of_error = Exec.sexp_of_error end |
