Skip to content

Commit 15fca74

Browse files
committed
Fix error reporting
In the new PPX IDL, all errors that are defined in `Network_interface` need to be raise as `Network_error`. If not, they will all be turned into `Network_error.Internal_error` exceptions. Signed-off-by: Rob Hoes <[email protected]>
1 parent 1e240d3 commit 15fca74

File tree

2 files changed

+18
-22
lines changed

2 files changed

+18
-22
lines changed

lib/network_utils.ml

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,6 @@ open Network_interface
1919

2020
module D = Debug.Make(struct let name = "network_utils" end)
2121
open D
22-
exception Script_missing of string
23-
exception Script_error of (string * string) list
24-
exception Read_error of string
25-
exception Write_error of string
26-
exception Not_implemented
27-
exception Vlan_in_use of (string * int)
28-
exception PVS_proxy_connection_error
2922

3023
type util_error =
3124
| Bus_out_of_range
@@ -78,7 +71,7 @@ let check_n_run run_func script args =
7871
| Unix.Unix_error (e, a, b) ->
7972
error "Caught unix error: %s [%s, %s]" (Unix.error_message e) a b;
8073
error "Assuming script %s doesn't exist" script;
81-
raise (Script_missing script)
74+
raise (Network_error (Script_missing script))
8275
| Forkhelpers.Spawn_internal_error(stderr, stdout, e)->
8376
let message =
8477
match e with
@@ -88,8 +81,11 @@ let check_n_run run_func script args =
8881
in
8982
error "Call '%s %s' exited badly: %s [stdout = '%s'; stderr = '%s']" script
9083
(String.concat " " args) message stdout stderr;
91-
raise (Script_error ["script", script; "args", String.concat " " args; "code",
92-
message; "stdout", stdout; "stderr", stderr])
84+
raise (Network_error (Script_error ["script", script;
85+
"args", String.concat " " args;
86+
"code", message;
87+
"stdout", stdout;
88+
"stderr", stderr]))
9389

9490
let call_script ?(log_successful_output=false) ?(timeout=Some 60.0) script args =
9591
let call_script_internal env script args =
@@ -136,18 +132,18 @@ module Sysfs = struct
136132
with
137133
| End_of_file -> ""
138134
(* Match the exception when the device state if off *)
139-
| Sys_error("Invalid argument") -> raise (Read_error file)
135+
| Sys_error("Invalid argument") -> raise (Network_error (Read_error file))
140136
| exn ->
141137
error "Error in read one line of file: %s, exception %s\n%s"
142138
file (Printexc.to_string exn) (Printexc.get_backtrace ());
143-
raise (Read_error file)
139+
raise (Network_error (Read_error file))
144140

145141
let write_one_line file l =
146142
let outchan = open_out file in
147143
try
148144
output_string outchan (l ^ "\n");
149145
close_out outchan
150-
with exn -> close_out outchan; raise (Write_error file)
146+
with exn -> close_out outchan; raise (Network_error (Write_error file))
151147

152148
let is_physical name =
153149
try

networkd/network_server.ml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ module Bridge = struct
735735
* device name or not on the requested bridge is bad. *)
736736
if parent' = parent && vlan' = vlan &&
737737
(device <> vlan_name || not (List.mem device bridge_interfaces)) then
738-
raise (Vlan_in_use (parent, vlan))
738+
raise (Network_error (Vlan_in_use (parent, vlan)))
739739
) (Proc.get_vlans ());
740740
(* Robustness enhancement: ensure there are no other VLANs in the bridge *)
741741
let current_interfaces = List.filter (fun n ->
@@ -817,7 +817,7 @@ module Bridge = struct
817817
Debug.with_thread_associated dbg (fun () ->
818818
match !backend_kind with
819819
| Openvswitch -> Ovs.bridge_to_ports name
820-
| Bridge -> raise Not_implemented
820+
| Bridge -> raise (Network_error Not_implemented)
821821
) ()
822822

823823
let get_all_ports dbg from_cache =
@@ -828,14 +828,14 @@ module Bridge = struct
828828
else
829829
match !backend_kind with
830830
| Openvswitch -> List.concat (List.map Ovs.bridge_to_ports (Ovs.list_bridges ()))
831-
| Bridge -> raise Not_implemented
831+
| Bridge -> raise (Network_error Not_implemented)
832832
) ()
833833

834834
let get_bonds _ dbg ~name =
835835
Debug.with_thread_associated dbg (fun () ->
836836
match !backend_kind with
837837
| Openvswitch -> Ovs.bridge_to_ports name
838-
| Bridge -> raise Not_implemented
838+
| Bridge -> raise (Network_error Not_implemented)
839839
) ()
840840

841841
let get_all_bonds dbg from_cache =
@@ -847,7 +847,7 @@ module Bridge = struct
847847
else
848848
match !backend_kind with
849849
| Openvswitch -> List.concat (List.map Ovs.bridge_to_ports (Ovs.list_bridges ()))
850-
| Bridge -> raise Not_implemented
850+
| Bridge -> raise (Network_error Not_implemented)
851851
) ()
852852

853853
type bond_link_info = {
@@ -892,7 +892,7 @@ module Bridge = struct
892892
Debug.with_thread_associated dbg (fun () ->
893893
match !backend_kind with
894894
| Openvswitch -> Ovs.bridge_to_vlan name
895-
| Bridge -> raise Not_implemented
895+
| Bridge -> raise (Network_error Not_implemented)
896896
) ()
897897

898898
let add_default_flows _ dbg bridge mac interfaces =
@@ -962,7 +962,7 @@ module Bridge = struct
962962
Ovs.mod_port real_bridge name "no-flood";
963963
Interface.bring_up () dbg ~name
964964
| Bridge ->
965-
raise Not_implemented
965+
raise (Network_error Not_implemented)
966966

967967
let add_port dbg bond_mac bridge name interfaces bond_properties kind =
968968
Debug.with_thread_associated dbg (fun () ->
@@ -1052,7 +1052,7 @@ module Bridge = struct
10521052
| "secure" -> Some Secure
10531053
| _ -> None
10541054
end
1055-
| Bridge -> raise Not_implemented
1055+
| Bridge -> raise (Network_error Not_implemented)
10561056
) ()
10571057

10581058
let is_persistent _ dbg ~name =
@@ -1121,7 +1121,7 @@ module PVS_proxy = struct
11211121
Jsonrpc_client.with_rpc ~path:!path ~call ()
11221122
with e ->
11231123
error "Error when calling PVS proxy: %s" (Printexc.to_string e);
1124-
raise PVS_proxy_connection_error
1124+
raise (Network_error PVS_proxy_connection_error)
11251125

11261126
let configure_site dbg config =
11271127
debug "Configuring PVS proxy for site %s" config.site_uuid;

0 commit comments

Comments
 (0)