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

Commit

Permalink
Merge pull request #5526 from ethereum/private-chain
Browse files Browse the repository at this point in the history
Log json exception details on chain config file load error
  • Loading branch information
halfalicious authored Mar 28, 2019
2 parents 65f752e + fb7b876 commit 523c965
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 5 deletions.
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

0 comments on commit 523c965

Please sign in to comment.