@@ -634,32 +634,35 @@ struct
634
634
let open Io.O in
635
635
Io. stats_kind lock_dir_path
636
636
>> | function
637
- | Ok S_DIR -> ()
637
+ | Ok S_DIR -> Ok ()
638
638
| Error (Unix. ENOENT, _ , _ ) ->
639
- User_error. raise
640
- ~hints:
641
- [ Pp. concat
642
- ~sep: Pp. space
643
- [ Pp. text " Run"
644
- ; User_message. command " dune pkg lock"
645
- ; Pp. text " to generate it."
646
- ]
647
- |> Pp. hovbox
648
- ]
649
- [ Pp. textf " %s does not exist." (Path.Source. to_string lock_dir_path) ]
639
+ Error
640
+ (User_error. make
641
+ ~hints:
642
+ [ Pp. concat
643
+ ~sep: Pp. space
644
+ [ Pp. text " Run"
645
+ ; User_message. command " dune pkg lock"
646
+ ; Pp. text " to generate it."
647
+ ]
648
+ |> Pp. hovbox
649
+ ]
650
+ [ Pp. textf " %s does not exist." (Path.Source. to_string lock_dir_path) ])
650
651
| Error e ->
651
- User_error. raise
652
- [ Pp. textf " %s is not accessible" (Path.Source. to_string lock_dir_path)
653
- ; Pp. textf " reason: %s" (Unix_error.Detailed. to_string_hum e)
654
- ]
652
+ Error
653
+ (User_error. make
654
+ [ Pp. textf " %s is not accessible" (Path.Source. to_string lock_dir_path)
655
+ ; Pp. textf " reason: %s" (Unix_error.Detailed. to_string_hum e)
656
+ ])
655
657
| _ ->
656
- User_error. raise
657
- [ Pp. textf " %s is not a directory." (Path.Source. to_string lock_dir_path) ]
658
+ Error
659
+ (User_error. make
660
+ [ Pp. textf " %s is not a directory." (Path.Source. to_string lock_dir_path) ])
658
661
;;
659
662
660
663
let check_packages packages ~lock_dir_path =
661
664
match validate_packages packages with
662
- | Ok () -> ()
665
+ | Ok () -> Ok ()
663
666
| Error (`Missing_dependencies missing_dependencies ) ->
664
667
List. iter missing_dependencies ~f: (fun { dependant_package; dependency; loc } ->
665
668
User_message. prerr
@@ -673,50 +676,60 @@ struct
673
676
(Package_name. to_string dependency)
674
677
(Path.Source. to_string_maybe_quoted lock_dir_path)
675
678
]));
676
- User_error. raise
677
- ~hints:
678
- [ Pp. concat
679
- ~sep: Pp. space
680
- [ Pp. text
681
- " This could indicate that the lockdir is corrupted. Delete it and then \
682
- regenerate it by running:"
683
- ; User_message. command " dune pkg lock"
684
- ]
685
- ]
686
- [ Pp. textf
687
- " At least one package dependency is itself not present as a package in the \
688
- lockdir %s."
689
- (Path.Source. to_string_maybe_quoted lock_dir_path)
690
- ]
679
+ Error
680
+ (User_error. make
681
+ ~hints:
682
+ [ Pp. concat
683
+ ~sep: Pp. space
684
+ [ Pp. text
685
+ " This could indicate that the lockdir is corrupted. Delete it and \
686
+ then regenerate it by running:"
687
+ ; User_message. command " dune pkg lock"
688
+ ]
689
+ ]
690
+ [ Pp. textf
691
+ " At least one package dependency is itself not present as a package in \
692
+ the lockdir %s."
693
+ (Path.Source. to_string_maybe_quoted lock_dir_path)
694
+ ])
691
695
;;
692
696
693
697
let load lock_dir_path =
694
698
let open Io.O in
695
- let * () = check_path lock_dir_path in
696
- let * version, dependency_hash, ocaml, repos, expanded_solver_variable_bindings =
697
- load_metadata (Path.Source. relative lock_dir_path metadata_filename)
698
- in
699
- let + packages =
700
- Io. readdir_with_kinds lock_dir_path
701
- >> | List. filter_map ~f: (fun (name , (kind : Unix.file_kind )) ->
702
- match kind with
703
- | S_REG -> Package_filename. to_package_name name |> Result. to_option
704
- | _ ->
705
- (* TODO *)
706
- None )
707
- >> = Io. parallel_map ~f: (fun package_name ->
708
- let + pkg = load_pkg ~version ~lock_dir_path package_name in
709
- package_name, pkg)
710
- >> | Package_name.Map. of_list_exn
711
- in
712
- check_packages packages ~lock_dir_path ;
713
- { version
714
- ; dependency_hash
715
- ; packages
716
- ; ocaml
717
- ; repos
718
- ; expanded_solver_variable_bindings
719
- }
699
+ let * result = check_path lock_dir_path in
700
+ match result with
701
+ | Error e -> Io. return (Error e)
702
+ | Ok () ->
703
+ let * version, dependency_hash, ocaml, repos, expanded_solver_variable_bindings =
704
+ load_metadata (Path.Source. relative lock_dir_path metadata_filename)
705
+ in
706
+ let + packages =
707
+ Io. readdir_with_kinds lock_dir_path
708
+ >> | List. filter_map ~f: (fun (name , (kind : Unix.file_kind )) ->
709
+ match kind with
710
+ | S_REG -> Package_filename. to_package_name name |> Result. to_option
711
+ | _ ->
712
+ (* TODO *)
713
+ None )
714
+ >> = Io. parallel_map ~f: (fun package_name ->
715
+ let + pkg = load_pkg ~version ~lock_dir_path package_name in
716
+ package_name, pkg)
717
+ >> | Package_name.Map. of_list_exn
718
+ in
719
+ check_packages packages ~lock_dir_path
720
+ |> Result. map ~f: (fun () ->
721
+ { version
722
+ ; dependency_hash
723
+ ; packages
724
+ ; ocaml
725
+ ; repos
726
+ ; expanded_solver_variable_bindings
727
+ })
728
+ ;;
729
+
730
+ let load_exn lock_dir_path =
731
+ let open Io.O in
732
+ load lock_dir_path >> | User_error. ok_exn
720
733
;;
721
734
end
722
735
@@ -740,7 +753,7 @@ module Load_immediate = Make_load (struct
740
753
let with_lexbuf_from_file path ~f = Io. with_lexbuf_from_file (Path. source path) ~f
741
754
end )
742
755
743
- let read_disk = Load_immediate. load
756
+ let read_disk = Load_immediate. load_exn
744
757
745
758
let transitive_dependency_closure t start =
746
759
let missing_packages =
0 commit comments