summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/kDL.ml8
-rw-r--r--lib/manifest.ml13
-rw-r--r--lib/nixtamal.ml6
3 files changed, 12 insertions, 15 deletions
diff --git a/lib/kDL.ml b/lib/kDL.ml
index a00d1ff..5f94557 100644
--- a/lib/kDL.ml
+++ b/lib/kDL.ml
@@ -5,13 +5,15 @@
(* extend & fix casing for ocaml-kdl *)
include Kdl
-let of_flow flow =
+let of_flow flow : (t, [> `ParseError of string]) result =
try
- Eio.Buf_read.parse_exn
+ match Eio.Buf_read.parse_exn
(fun buf -> Eio.Buf_read.take_all buf |> Kdl.of_string)
~max_size: max_int
flow
- |> Result.ok
+ with
+ | Ok doc -> Ok doc
+ | Error _ -> Error (`ParseError "KDL parse error")
with
| Kdl.Parse_error (msg, _) -> Error (`ParseError msg)
diff --git a/lib/manifest.ml b/lib/manifest.ml
index 7bf2997..c2c7c79 100644
--- a/lib/manifest.ml
+++ b/lib/manifest.ml
@@ -865,17 +865,14 @@ let exists () : bool =
Eio.Path.is_file filepath
let read () =
- let (let*) = Result.bind in
let working_dir = Working_directory.get () in
let filepath = Eio.Path.(working_dir / filename) in
Logs.info (fun m -> m "Reading manifest @@ %a …" Eio.Path.pp filepath);
- let kdl_result =
- Eio.Path.with_open_in filepath @@ fun flow ->
- KDL.of_flow flow
- in
- let* kdl = kdl_result |> Result.map_error (fun (`ParseError msg) -> `Parsing [`ParseError msg]) in
- let () = manifest := Some kdl in
- Ok kdl
+ match Eio.Path.with_open_in filepath KDL.of_flow with
+ | Error (`ParseError msg) -> Error (`Parsing [`ParseError msg])
+ | Ok kdl ->
+ let () = manifest := Some kdl in
+ Ok kdl
let make ?(version = "0.1.1") () =
Logs.app (fun m -> m "Making manifest file @@ version:%s" version);
diff --git a/lib/nixtamal.ml b/lib/nixtamal.ml
index a9435ab..9ef08e7 100644
--- a/lib/nixtamal.ml
+++ b/lib/nixtamal.ml
@@ -53,9 +53,7 @@ let read_manifest_and_lockfile () : (Name.Name.t list, error) result =
| Ok(kdl : KDL.t) ->
Manifest.document_to_t kdl
|> Result.map_error (fun err -> `Parsing err)
- | Error(e : KDL.error) ->
- let v_errs : KDL.Valid.err list = [`ParseError e] in
- Error (`Parsing v_errs)
+ | Error err -> Error err
end
in
let* lockfile_opt =
@@ -350,7 +348,7 @@ let upgrade ?from ?(to_ = Schema.Version.current) ?(dry_run = false) () : (unit,
let* () =
match Manifest.read () with
| Ok _ -> Logs.info (fun m -> m "Manifest verified."); Ok ()
- | Error e -> Error (`Manifest (`Parsing [`ParseError e]))
+ | Error e -> Error (`Manifest e)
in
let* () =
match Lockfile.read () with