Skip to content

Commit

Permalink
keep original error message (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
trobro authored Feb 13, 2020
1 parent 5aec4d9 commit db4467e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/hjson_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ static Value _hasTrailing(Parser *p) {
// Braces for the root object are optional
static Value _rootValue(Parser *p) {
Value res;
std::string errMsg;

_white(p);

Expand All @@ -519,7 +520,9 @@ static Value _rootValue(Parser *p) {
if (!_hasTrailing(p)) {
return res;
}
} catch(syntax_error e) {}
} catch(syntax_error e) {
errMsg = std::string(e.what());
}

// test if we are dealing with a single JSON value instead (true/false/null/num/"")
_resetAt(p);
Expand All @@ -528,6 +531,10 @@ static Value _rootValue(Parser *p) {
return res;
}

if (!errMsg.empty()) {
throw syntax_error(errMsg);
}

throw syntax_error(_errAt(p, "Syntax error, found trailing characters"));
}

Expand Down

0 comments on commit db4467e

Please sign in to comment.