diff --git a/source/configy/read.d b/source/configy/read.d index 5f842a6..7885d8b 100644 --- a/source/configy/read.d +++ b/source/configy/read.d @@ -653,7 +653,7 @@ private TLFR.Type parseMapping (alias TLFR) { dbgWrite("%s: Calling `%s` method", TLFR.Type.stringof.paint(Cyan), "validate()".paint(Green)); - result.validate(); + wrapConstruct(result.validate(), path, Location.get(node)); } else { diff --git a/source/configy/test.d b/source/configy/test.d index 330acbf..1145aaa 100644 --- a/source/configy/test.d +++ b/source/configy/test.d @@ -332,11 +332,22 @@ unittest public int value; } + static struct ThrowingValidate + { + void validate() const + { + throw new Exception("Bad data, try again"); + } + + public int value; + } + static struct InnerConfig { public int value; @Optional ThrowingCtor ctor; @Optional ThrowingFromString fromString; + @Optional ThrowingValidate validated; @Converter!int( (Node value) { @@ -374,6 +385,16 @@ unittest assert(exc.toString() == "/dev/null(2:14): config.fromString: Some meaningful error message"); } + try + { + auto result = parseConfigString!Config("config:\n value: 42\n validated:\n value: 42", "/dev/null"); + assert(0); + } + catch (ConfigException exc) + { + assert(exc.toString() == "/dev/null(3:4): config.validated: Bad data, try again"); + } + try { auto result = parseConfigString!Config("config:\n value: 42\n converter: 42", "/dev/null");