diff options
-rw-r--r-- | lib/configuration/read_conf.ml | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/configuration/read_conf.ml b/lib/configuration/read_conf.ml index f78ff5b..0771565 100644 --- a/lib/configuration/read_conf.ml +++ b/lib/configuration/read_conf.ml @@ -183,16 +183,19 @@ module Make (S : Decoders.Decode.S) = struct loadFile : string -> S.value; } - type dataSet = S.value * (string * string) list + type dataSet = S.value * (string * (S.value * string)) list class loader (context : loader_context) = object (self) - method path_checker : string S.decoder -> string S.decoder = + method path_checker : (S.value * string) S.decoder -> string S.decoder = fun check -> Decoders.Decoder.bind - (fun path -> + (fun (value, path) -> if context.checkFile path then Decoders.Decoder.pure path - else Decoders.Decoder.fail "Expected a path to an existing file") + else + let message = "Expected a path to an existing file" in + let err = Decoders.Error.make ~context:value message in + S.fail_with err) check (** Check if a file given in the configuration exists: an error is raised if the function [checkFile] retun false. @@ -218,11 +221,13 @@ module Make (S : Decoders.Decode.S) = struct | false -> S.succeed s in let list_files_decoders = - self#keep (S.key_value_pairs' no_dash_decoder S.string) + self#keep (S.key_value_pairs' no_dash_decoder (self#keep S.string)) in let get_field = S.field "files" list_files_decoders in - let* result = S.map context.loadFile (self#path_checker S.string) in + let* result = + S.map context.loadFile (self#path_checker (self#keep S.string)) + in let files = get_field result in let dataSetResult = Result.map (fun v -> Some v) files in S.from_result dataSetResult @@ -256,7 +261,7 @@ module Make (S : Decoders.Decode.S) = struct (S.one_of [ (* If the file is declared, use it *) - ("file", S.field "file" S.string); + ("file", self#keep (S.field "file" S.string)); ( "dataset", (* Otherwise search in the data set *) |