summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/vyconf_tree.ml9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/vyconf_tree.ml b/src/vyconf_tree.ml
index 449f095..f634d55 100644
--- a/src/vyconf_tree.ml
+++ b/src/vyconf_tree.ml
@@ -1,5 +1,9 @@
type 'a vyconf_tree = Node of string * 'a * ('a vyconf_tree list)
+exception Empty_path
+exception Duplicate_child
+exception Nonexistent_path
+
let name_of_node (Node (name, _, _)) = name
let children_of_node (Node (_, _, children)) = children
@@ -47,14 +51,15 @@ let replace_child node child =
let rec insert_child default_data node path data =
match path with
- | [] -> raise (Failure "Can't insert at empty path")
+ | [] -> raise Empty_path
| [name] -> insert_immediate_child node name data
| name :: names ->
let next_child = find_child node name in
match next_child with
| Some next_child' ->
let new_node = insert_child default_data next_child' names data in
- replace_child node new_node
+ if names = [] then raise Duplicate_child
+ else replace_child node new_node
| None ->
let next_child' = Node (name, default_data, []) in
let new_node = insert_child default_data next_child' names data in