Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(pkg): remove an unnecessary [result] variable #9686

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 20 additions & 22 deletions src/dune_pkg/opam_solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -617,24 +617,26 @@ let opam_package_to_lock_file_pkg
;;

let solve_package_list packages context =
let* result =
Fiber.collect_errors (fun () ->
(* [Solver.solve] returns [Error] when it's unable to find a solution to
the dependencies, but can also raise exceptions, for example if opam
is unable to parse an opam file in the package repository. To prevent
an unexpected opam exception from crashing dune, we catch all
exceptions raised by the solver and report them as [User_error]s
instead. *)
Solver.solve context packages)
>>| function
| Ok (Ok res) -> Ok res
| Ok (Error e) -> Error (`Diagnostics e)
| Error [] -> assert false
| Error (exn :: _) ->
(* CR-rgrinberg: this needs to be handled right *)
Error (`Exn exn.exn)
in
match result with
Fiber.collect_errors (fun () ->
(* [Solver.solve] returns [Error] when it's unable to find a solution to
the dependencies, but can also raise exceptions, for example if opam
is unable to parse an opam file in the package repository. To prevent
an unexpected opam exception from crashing dune, we catch all
exceptions raised by the solver and report them as [User_error]s
instead. *)
Solver.solve context packages)
>>| (function
| Ok (Ok res) -> Ok res
| Ok (Error e) -> Error (`Diagnostics e)
| Error [] -> assert false
| Error (exn :: _) ->
(* CR-rgrinberg: this needs to be handled right *)
Error (`Exn exn.exn))
>>= function
| Ok packages -> Fiber.return @@ Ok (Solver.packages_of_result packages)
| Error (`Diagnostics e) ->
let+ diagnostics = Solver.diagnostics e in
Error (`Diagnostic_message (Pp.text diagnostics))
| Error (`Exn exn) ->
(match exn with
| OpamPp.(Bad_format _ | Bad_format_list _ | Bad_version _) as bad_format ->
Expand All @@ -644,10 +646,6 @@ let solve_package_list packages context =
Code_error.raise
"Unexpected exception raised while solving dependencies"
[ "exception", Exn.to_dyn unexpected_exn ])
| Error (`Diagnostics e) ->
let+ diagnostics = Solver.diagnostics e in
Error (`Diagnostic_message (Pp.text diagnostics))
| Ok packages -> Fiber.return @@ Ok (Solver.packages_of_result packages)
;;

module Solver_result = struct
Expand Down
Loading