Skip to content

Commit 4ea1acc

Browse files
committed
Use ~message and ~here in Option.value_exn
The ~here is set to the point of usage of Option.value_exn itself to conform with our code base's current practices, but we might want to have it passed in from the caller of these functions.
1 parent 73957e6 commit 4ea1acc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/lib/merkle_ledger/database.ml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,9 @@ module Make (Inputs : Intf.Inputs.DATABASE) = struct
282282
let addr = Addr.of_int_exn ~ledger_depth:mdb.depth index in
283283
get mdb (Location.Account addr)
284284

285-
let get_at_index_exn mdb index = get_at_index mdb index |> Option.value_exn
285+
let get_at_index_exn mdb index =
286+
get_at_index mdb index
287+
|> Option.value_exn ~message:"Expected account at index" ~here:[%here]
286288

287289
let all_accounts (t : t) =
288290
match Account_location.last_location_address t with
@@ -584,7 +586,9 @@ module Make (Inputs : Intf.Inputs.DATABASE) = struct
584586

585587
let iteri t ~f =
586588
iteri_untrusted t ~f:(fun index account_opt ->
587-
f index (Option.value_exn account_opt) )
589+
f index
590+
(Option.value_exn ~message:"Expected account at index" ~here:[%here]
591+
account_opt ) )
588592

589593
(* TODO : if key-value store supports iteration mechanism, like RocksDB,
590594
maybe use that here, instead of loading all accounts into memory See Issue

src/lib/merkle_mask/masking_merkle_tree.ml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -886,7 +886,8 @@ module Make (Inputs : Inputs_intf.S) = struct
886886

887887
let get_at_index_exn t index =
888888
assert_is_attached t ;
889-
get_at_index t index |> Option.value_exn
889+
get_at_index t index
890+
|> Option.value_exn ~message:"Expected account at index" ~here:[%here]
890891

891892
let set_at_index_exn t index account =
892893
assert_is_attached t ;
@@ -918,7 +919,9 @@ module Make (Inputs : Inputs_intf.S) = struct
918919

919920
let iteri t ~f =
920921
iteri_untrusted t ~f:(fun index account_opt ->
921-
f index (Option.value_exn account_opt) )
922+
f index
923+
(Option.value_exn ~message:"Expected account at index" ~here:[%here]
924+
account_opt ) )
922925

923926
let foldi_with_ignored_accounts t ignored_accounts ~init ~f =
924927
assert_is_attached t ;

0 commit comments

Comments
 (0)