From 3df27ffb2bd40f3eaeed6dfb08ef3041cc60bfe0 Mon Sep 17 00:00:00 2001 From: ยท๐‘‘๐‘ด๐‘•๐‘‘๐‘ฉ๐‘ค Date: Wed, 10 Dec 2025 13:00:26 +0000 Subject: ocaml onset --- lib/error.ml | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 lib/error.ml (limited to 'lib/error.ml') diff --git a/lib/error.ml b/lib/error.ml new file mode 100644 index 0000000..4255c79 --- /dev/null +++ b/lib/error.ml @@ -0,0 +1,77 @@ +(*โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ” +โ”‚ SPDX-FileCopyrightText: 2025 toastal โ”‚ +โ”‚ SPDX-License-Identifier: LGPL-2.1-or-later WITH OCaml-LGPL-linking-exception โ”‚ +โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€*) +open Name + +type manifest_error = [ + | `Parsing of Util.KDL.Valid.err list + | `Not_set_up + | `File_already_exists +] +[@@deriving show] + +type lockfile_error = [ + | `Parsing of string + | `Serializing of string +] +[@@deriving show] + +type prefetch_method = [ + | `URL + | `Git + | `Darcs + | `Pijul +] +[@@deriving show] + +type prefetch_error = [ + | `Empty_output of prefetch_method + | `Stderr of prefetch_method * string + | `JSON_parsing of prefetch_method * string + | `Darcs_context of string + | `Exception of prefetch_method * string +] +[@@deriving show] + +type input_foreman_error = [ + | `Could_not_add of Name.t + | `Could_not_drop of Name.t + | `Could_not_get of Name.t + | `Could_not_set of Name.t + | `Latest_cmd_empty of Name.t + | `Latest_cmd_fail of Name.t * string + | `Latest_cmd_stderr of Name.t * string + | `Prefetch of Name.t * prefetch_error + | `Pool_exception of string + (* FIXME: string list *) + | `Many_errors of string list +] +[@@deriving show] + +type error = [ + | `Manifest of manifest_error + | `Lockfile of lockfile_error + | `Version_mismatch of string * string + | `Input_foreman of input_foreman_error +] +[@@deriving show] + +let [@inline]tag_manifest (res : ('a, manifest_error) result) = + Result.map_error (fun err -> `Manifest err) res + +let [@inline]tag_lockfile (res : ('a, lockfile_error) result) = + Result.map_error (fun err -> `Lockfile err) res + +let [@inline]tag_input_foreman res = + Result.map_error (fun err -> `Input_foreman err) res + +let pp ppf = function + | `Manifest err -> + Fmt.(pf ppf "%a" pp_manifest_error err) + | `Lockfile err -> + Fmt.(pf ppf "%a" pp_lockfile_error err) + | `Version_mismatch (mnfst, lock) -> + Fmt.pf ppf "Version mismatch: Manifest@@%s & Lockfile@@%s" mnfst lock + | `Input_foreman (`CouldNotAdd name) -> + Fmt.pf ppf "Could not set %a" Name.pp name -- cgit v1.2.3