Refactor not found logic
This commit is contained in:
parent
9416e0552d
commit
234c7a0cb2
3 changed files with 24 additions and 19 deletions
|
@ -85,6 +85,13 @@ let if_error
|
||||||
Lwt_result.fail (message, status)
|
Lwt_result.fail (message, status)
|
||||||
| Ok _ as r -> Lwt.return r
|
| Ok _ as r -> Lwt.return r
|
||||||
|
|
||||||
|
let not_found_error r =
|
||||||
|
let* r = r in
|
||||||
|
match r with
|
||||||
|
| Error `Not_found ->
|
||||||
|
Lwt_result.fail ("Resource not found", `Not_Found)
|
||||||
|
| Ok _ as r -> Lwt.return r
|
||||||
|
|
||||||
let get_uuid s =
|
let get_uuid s =
|
||||||
Lwt.return
|
Lwt.return
|
||||||
(if String.length s = 36 then
|
(if String.length s = 36 then
|
||||||
|
@ -99,11 +106,11 @@ let main_binary_of_uuid uuid db =
|
||||||
|> if_error "Error getting job build"
|
|> if_error "Error getting job build"
|
||||||
~log:(fun e -> Log.warn (fun m -> m "Error getting job build: %a" pp_error e))
|
~log:(fun e -> Log.warn (fun m -> m "Error getting job build: %a" pp_error e))
|
||||||
>>= fun (_id, build) ->
|
>>= fun (_id, build) ->
|
||||||
match build.Builder_db.Build.main_binary with
|
Model.not_found build.Builder_db.Build.main_binary
|
||||||
| None -> Lwt_result.fail ("Resource not found", `Not_Found)
|
|> not_found_error
|
||||||
| Some main_binary ->
|
>>= fun main_binary ->
|
||||||
Model.build_artifact_by_id main_binary db
|
Model.build_artifact_by_id main_binary db
|
||||||
|> if_error "Error getting main binary"
|
|> if_error "Error getting main binary"
|
||||||
|
|
||||||
module Viz_aux = struct
|
module Viz_aux = struct
|
||||||
|
|
||||||
|
@ -203,12 +210,11 @@ module Viz_aux = struct
|
||||||
artifacts
|
artifacts
|
||||||
in
|
in
|
||||||
begin
|
begin
|
||||||
match debug_binary with
|
Model.not_found debug_binary
|
||||||
| None -> Lwt_result.fail ("Error getting debug-binary", `Not_Found)
|
|> not_found_error >>= fun debug_binary ->
|
||||||
| Some debug_binary ->
|
debug_binary.sha256
|
||||||
debug_binary.sha256
|
|> hex
|
||||||
|> hex
|
|> Lwt_result.return
|
||||||
|> Lwt_result.return
|
|
||||||
end
|
end
|
||||||
| `Dependencies ->
|
| `Dependencies ->
|
||||||
let opam_switch =
|
let opam_switch =
|
||||||
|
@ -216,12 +222,11 @@ module Viz_aux = struct
|
||||||
(fun p -> Fpath.(equal (v "opam-switch") (base p.localpath)))
|
(fun p -> Fpath.(equal (v "opam-switch") (base p.localpath)))
|
||||||
artifacts
|
artifacts
|
||||||
in
|
in
|
||||||
match opam_switch with
|
Model.not_found opam_switch
|
||||||
| None -> Lwt_result.fail ("Error getting opam-switch", `Not_Found)
|
|> not_found_error >>= fun opam_switch ->
|
||||||
| Some opam_switch ->
|
opam_switch.sha256
|
||||||
opam_switch.sha256
|
|> hex
|
||||||
|> hex
|
|> Lwt_result.return
|
||||||
|> Lwt_result.return
|
|
||||||
|
|
||||||
let try_load_cached_visualization ~cachedir ~uuid viz_typ db =
|
let try_load_cached_visualization ~cachedir ~uuid viz_typ db =
|
||||||
Lwt.return (get_viz_version_from_dirs ~cachedir ~viz_typ)
|
Lwt.return (get_viz_version_from_dirs ~cachedir ~viz_typ)
|
||||||
|
|
|
@ -15,7 +15,7 @@ let pp_error ppf = function
|
||||||
Caqti_error.pp ppf e
|
Caqti_error.pp ppf e
|
||||||
|
|
||||||
let not_found = function
|
let not_found = function
|
||||||
| None -> Lwt.return (Error `Not_found :> (_, [> error ]) result)
|
| None -> Lwt_result.fail `Not_found
|
||||||
| Some v -> Lwt_result.return v
|
| Some v -> Lwt_result.return v
|
||||||
|
|
||||||
let staging datadir = Fpath.(datadir / "_staging")
|
let staging datadir = Fpath.(datadir / "_staging")
|
||||||
|
|
|
@ -2,7 +2,7 @@ type error = [ Caqti_error.call_or_retrieve | `Not_found | `File_error of Fpath.
|
||||||
|
|
||||||
val pp_error : Format.formatter -> error -> unit
|
val pp_error : Format.formatter -> error -> unit
|
||||||
|
|
||||||
val not_found : 'a option -> ('a, [> error ]) result Lwt.t
|
val not_found : 'a option -> ('a, [> `Not_found ]) result Lwt.t
|
||||||
|
|
||||||
val staging : Fpath.t -> Fpath.t
|
val staging : Fpath.t -> Fpath.t
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue