Skip to content
This repository has been archived by the owner on Oct 28, 2021. It is now read-only.

Commit

Permalink
Log json exception details on chain config error
Browse files Browse the repository at this point in the history
Also return new error code AlethErrors::ConfigFileInvalid
  • Loading branch information
halfalicious committed Mar 27, 2019
1 parent ae042a3 commit 8fbe95d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
7 changes: 4 additions & 3 deletions aleth/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ int main(int argc, char** argv)
}
catch (...)
{
cerr << "provided configuration is not well formatted\n";
cerr << "sample: \n" << genesisInfo(eth::Network::MainNetworkTest) << "\n";
return AlethErrors::Success;
cerr << "provided configuration is not well-formatted\n";
cerr << "well-formatted sample: \n"
<< genesisInfo(eth::Network::MainNetworkTest) << "\n";
return AlethErrors::ConfigFileInvalid;
}
}

Expand Down
1 change: 1 addition & 0 deletions libdevcore/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ DEV_SIMPLE_EXCEPTION(FailedInvariant);
DEV_SIMPLE_EXCEPTION(ValueTooLarge);
DEV_SIMPLE_EXCEPTION(UnknownField);
DEV_SIMPLE_EXCEPTION(MissingField);
DEV_SIMPLE_EXCEPTION(SyntaxError);
DEV_SIMPLE_EXCEPTION(WrongFieldType);
DEV_SIMPLE_EXCEPTION(InterfaceNotSupported);
DEV_SIMPLE_EXCEPTION(ExternalFunctionFailure);
Expand Down
1 change: 1 addition & 0 deletions libethcore/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ enum AlethErrors
UnknownArgument,
UnknownMiningOption,
ConfigFileEmptyOrNotFound,
ConfigFileInvalid,
UnknownNetworkType,
BadNetworkIdOption,
BadConfigOption,
Expand Down
15 changes: 14 additions & 1 deletion libethereum/ChainParams.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,20 @@ ChainParams ChainParams::loadConfig(
{
ChainParams cp(*this);
js::mValue val;
js::read_string_or_throw(_json, val);

try
{
js::read_string_or_throw(_json, val);
}
catch (js::Error_position const& error)
{
std::string const comment = "json parsing error detected on line " +
std::to_string(error.line_) + " in column " +
std::to_string(error.column_) + ": " + error.reason_;
std::cerr << comment << "\n";
BOOST_THROW_EXCEPTION(SyntaxError() << errinfo_comment(comment));
}

js::mObject obj = val.get_obj();

validateConfigJson(obj);
Expand Down

0 comments on commit 8fbe95d

Please sign in to comment.