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

Log json exception details on chain config file load error #5526

Merged
merged 3 commits into from
Mar 28, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
- Fixed: [#5452](https://github.com/ethereum/aleth/pull/5452) Correctly handle Discovery messages when the peer changes public key.
- Fixed: [#5519](https://github.com/ethereum/aleth/pull/5519) Correctly handle Discovery messages with known public key but unknown endpoint.
- Fixed: [#5523](https://github.com/ethereum/aleth/pull/5523) [#5533](https://github.com/ethereum/aleth/pull/5533) Fix syncing terminating prematurely because of race condition.
- Added: [#5526](https://github.com/ethereum/aleth/pull/5526) Improved logging when loading chain config json containing syntax error.

[1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master
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
2 changes: 1 addition & 1 deletion test/unittests/libethereum/BlockChain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(invalidJsonThrows)
{
h256 emptyStateRoot;
/* Below, a comma is missing between fields. */
BOOST_CHECK_THROW(ChainParams("{ \"sealEngine\" : \"unknown\" \"accountStartNonce\" : \"3\" }", emptyStateRoot), json_spirit::Error_position);
BOOST_CHECK_THROW(ChainParams("{ \"sealEngine\" : \"unknown\" \"accountStartNonce\" : \"3\" }", emptyStateRoot), SyntaxError);
}

BOOST_AUTO_TEST_CASE(unknownFieldThrows)
Expand Down