Skip to content

Commit 7f96646

Browse files
committed
style: List.find/List.find_opt/s
Signed-off-by: Vincent Liu <shuntian.liu2@cloud.com>
1 parent 36d41aa commit 7f96646

3 files changed

Lines changed: 16 additions & 18 deletions

File tree

ocaml/xapi/storage_migrate.ml

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -411,12 +411,12 @@ module MigrateLocal = struct
411411
let sr, vdi = State.of_mirror_id id in
412412
let vdis = Local.SR.scan dbg sr in
413413
let local_vdi =
414-
try List.find (fun x -> x.vdi = vdi) vdis
415-
with Not_found ->
416-
failwith
417-
(Printf.sprintf "Local VDI %s not found"
418-
(Storage_interface.Vdi.string_of vdi)
419-
)
414+
match List.find_opt (fun x -> x.vdi = vdi) vdis with
415+
| None ->
416+
failwith_fmt "Local VDI %s not found"
417+
(Storage_interface.Vdi.string_of vdi)
418+
| Some v ->
419+
v
420420
in
421421
let local_vdi = add_to_sm_config local_vdi "mirror" "null" in
422422
let local_vdi = remove_from_sm_config local_vdi "base_mirror" in
@@ -425,16 +425,12 @@ module MigrateLocal = struct
425425
Local.VDI.destroy dbg sr snapshot.vdi ;
426426
(* Destroy the snapshot, if it still exists *)
427427
let snap =
428-
try
429-
Some
430-
(List.find
431-
(fun x ->
432-
List.mem_assoc "base_mirror" x.sm_config
433-
&& List.assoc "base_mirror" x.sm_config = id
434-
)
435-
vdis
436-
)
437-
with _ -> None
428+
List.find_opt
429+
(fun x ->
430+
List.mem_assoc "base_mirror" x.sm_config
431+
&& List.assoc "base_mirror" x.sm_config = id
432+
)
433+
vdis
438434
in
439435
( match snap with
440436
| Some s ->

ocaml/xapi/storage_migrate_helper.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ open Storage_interface
2424
open Xapi_stdext_pervasives.Pervasiveext
2525
open Xmlrpc_client
2626

27-
module State = struct
28-
let failwith_fmt fmt = Printf.ksprintf failwith fmt
27+
let failwith_fmt fmt = Printf.ksprintf failwith fmt
2928

29+
module State = struct
3030
module Receive_state = struct
3131
type t = {
3232
sr: Sr.t

ocaml/xapi/storage_migrate_helper.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
module SXM : Debug.DEBUG
1616

17+
val failwith_fmt : ('a, unit, string, 'b) format4 -> 'a
18+
1719
module State : sig
1820
module Receive_state : sig
1921
type t = {

0 commit comments

Comments
 (0)