Skip to content

Commit 69ab238

Browse files
committed
T7915: catch exceptions and add annotations indicated by alert exn
1 parent d738ddc commit 69ab238

File tree

3 files changed

+237
-71
lines changed

3 files changed

+237
-71
lines changed

src/commit.ml

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,14 @@ let add_tag_instance cd cs tv =
9797
CS.add { cd with tag_value = Some tv; } cs
9898

9999
let get_node_data rt ct src (path, cs') t =
100+
(* alert exn CT.is_tag_value;
101+
RT.refpath;
102+
RT.get_priority;
103+
RT.get_owner;
104+
RT.is_tag:
105+
[Vytree.Empty_path] not possible in branch of non-empty path
106+
[Vytree.Nonexistent_path] not possible in fold_tree_with_path
107+
*)
100108
if Vyos1x.Util.is_empty path then
101109
(path, cs')
102110
else
@@ -106,16 +114,16 @@ let get_node_data rt ct src (path, cs') t =
106114
let rpath = List.rev path in
107115
(* the following is critical to avoid redundant calculations for owner
108116
of a tag node, quadratic in the number of tag node values *)
109-
if CT.is_tag_value ct rpath then
117+
if (CT.is_tag_value[@alert "-exn"]) ct rpath then
110118
(path, cs')
111119
else
112-
let rt_path = RT.refpath rt rpath in
120+
let rt_path = (RT.refpath[@alert "-exn"]) rt rpath in
113121
let priority =
114-
match RT.get_priority rt rt_path with
122+
match (RT.get_priority[@alert "-exn"]) rt rt_path with
115123
| None -> 0
116124
| Some s -> int_of_string s
117125
in
118-
let owner = RT.get_owner rt rt_path in
126+
let owner = (RT.get_owner[@alert "-exn"]) rt rt_path in
119127
match owner with
120128
| None -> (path, cs')
121129
| Some owner_str ->
@@ -128,7 +136,7 @@ let get_node_data rt ct src (path, cs') t =
128136
source = src; }
129137
in
130138
let tag_values =
131-
match RT.is_tag rt rt_path with
139+
match (RT.is_tag[@alert "-exn"]) rt rt_path with
132140
| false -> []
133141
| true -> VT.list_children t
134142
in
@@ -147,21 +155,27 @@ let get_commit_set rt ct src =
147155
the path is in a subtree, however, insert in the add queue - cf. T5492
148156
*)
149157
let legacy_order del_t a b =
158+
(* alert exn Vytree.is_terminal_path:
159+
[Vytree.Empty_path] not possible as cdata.path non-empty
160+
*)
150161
let shift c_data (c_del, c_add) =
151162
let path =
152163
match c_data.tag_value with
153164
| None -> c_data.path
154165
| Some v -> c_data.path @ [v]
155166
in
156-
match VT.is_terminal_path del_t path with
167+
match (VT.is_terminal_path[@alert "-exn"]) del_t path with
157168
| false -> CS.remove c_data c_del, CS.add c_data c_add
158169
| true -> c_del, c_add
159170
in
160171
CS.fold shift a (a, b)
161172

162173
let calculate_priority_lists rt diff =
174+
(* alert exn CT.get_subtree:
175+
[Vytree.Empty_path] not possible for given path
176+
*)
163177
let del_tree = CD.get_tagged_delete_tree diff in
164-
let add_tree = CT.get_subtree diff ["add"] in
178+
let add_tree = (CT.get_subtree[@alert "-exn"]) diff ["add"] in
165179
let cs_del' = get_commit_set rt del_tree DELETE in
166180
let cs_add' = get_commit_set rt add_tree ADD in
167181
let cs_del, cs_add = legacy_order del_tree cs_del' cs_add' in
@@ -173,33 +187,49 @@ let calculate_priority_lists rt diff =
173187
on failure, deleted paths are added back in, added paths ignored
174188
*)
175189
let config_result_update c_data n_data =
190+
(* alert exn CT.get_subtree:
191+
[Vytree.Empty_path] not possible for given path
192+
alert exn CD.clone:
193+
[Vytree.Nonexistent_path] not possible for node_data.path
194+
alert exn CD.tree_union:
195+
[Tree_alg.Incompatible_union] not possible for base root
196+
[Tree_alg.Nonexistent_child] non reachable
197+
*)
176198
match n_data.reply with
177199
| None -> c_data (* already exluded in calling function *)
178200
| Some r ->
179201
match r.success, n_data.source with
180202
| true, ADD ->
181-
let add = CT.get_subtree c_data.config_diff ["add"] in
203+
let add =
204+
(CT.get_subtree[@alert "-exn"]) c_data.config_diff ["add"]
205+
in
182206
let path =
183207
match n_data.tag_value with
184208
| None -> n_data.path
185209
| Some v -> n_data.path @ [v]
186210
in
187-
let add_tree = CD.clone add (CT.default) path in
188-
let config = CD.tree_union add_tree c_data.config_result in
211+
let add_tree = (CD.clone[@alert "-exn"]) add (CT.default) path in
212+
let config =
213+
(CD.tree_union[@alert "-exn"]) add_tree c_data.config_result
214+
in
189215
let result =
190216
{ success = c_data.result.success && true;
191217
out = c_data.result.out ^ r.out; }
192218
in
193219
{ c_data with config_result = config; result = result; }
194220
| false, DELETE ->
195-
let sub = CT.get_subtree c_data.config_diff ["sub"] in
221+
let sub =
222+
(CT.get_subtree[@alert "-exn"]) c_data.config_diff ["sub"]
223+
in
196224
let path =
197225
match n_data.tag_value with
198226
| None -> n_data.path
199227
| Some v -> n_data.path @ [v]
200228
in
201-
let add_tree = CD.clone sub (CT.default) path in
202-
let config = CD.tree_union add_tree c_data.config_result in
229+
let add_tree = (CD.clone[@alert "-exn"]) sub (CT.default) path in
230+
let config =
231+
(CD.tree_union[@alert "-exn"]) add_tree c_data.config_result
232+
in
203233
let result =
204234
{ success = c_data.result.success && false;
205235
out = c_data.result.out ^ r.out; }
@@ -236,7 +266,13 @@ let commit_update c_data =
236266
in List.fold_left func c_data c_data.node_list
237267

238268
let make_commit_data ?(dry_run=false) rt at wt id pid sudo_user user =
239-
let diff = CD.diff_tree [] at wt in
269+
(* alert exn CD.diff_tree:
270+
[Config_diff.Incommensurable] not possible as base root
271+
[Config_diff.Empty_comparison] not reachable for path []
272+
alert exn CT.get_subtree:
273+
[Vytree.Empty_path] not possible for given path
274+
*)
275+
let diff = (CD.diff_tree[@alert "-exn"]) [] at wt in
240276
let del_list, add_list = calculate_priority_lists rt diff in
241277
{ session_id = id;
242278
session_pid = pid;
@@ -247,6 +283,6 @@ let make_commit_data ?(dry_run=false) rt at wt id pid sudo_user user =
247283
background = false;
248284
init = None;
249285
config_diff = diff;
250-
config_result = CT.get_subtree diff ["inter"];
286+
config_result = (CT.get_subtree[@alert "-exn"]) diff ["inter"];
251287
node_list = del_list @ add_list;
252288
result = default_status; }

0 commit comments

Comments
 (0)