Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

configy: Catch and re-throw validation errors #65

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/configy/read.d
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
21 changes: 21 additions & 0 deletions source/configy/test.d
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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");
Expand Down
Loading