Commit 56d72622 authored by POTTIER Francois's avatar POTTIER Francois

Numbering: raise a more informative exception when [encode] or [decode] is...

Numbering: raise a more informative exception when [encode] or [decode] is given an invalid argument.
parent c5d81829
......@@ -59,10 +59,36 @@ module Make (M : IMPERATIVE_MAPS) = struct
Array.map force reverse
module Done () = struct
type t = M.key
let n = current()
let encode = encode
let decode = Array.get (reverse_mapping())
let encode x =
(* It would be an error to try and encode new keys now. Thus, if
[x] has not been encountered before, the client is at fault.
Fail with a nice informative message. *)
if has_been_encoded x then
encode x
else
Printf.sprintf
"Fix.Numbering: invalid argument passed to \"encode\".\n%s\n"
__LOC__
|> invalid_arg
let reverse =
reverse_mapping()
let decode i =
if 0 <= i && i < n then
reverse.(i)
else
Printf.sprintf
"Fix.Numbering: invalid argument passed to \"decode\".\n\
The index %d is not in the range [0, %d).\n%s\n"
i n __LOC__
|> invalid_arg
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment