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

Commit 523c965

Browse files
authored
Merge pull request #5526 from ethereum/private-chain
Log json exception details on chain config file load error
2 parents 65f752e + fb7b876 commit 523c965

File tree

6 files changed

+22
-5
lines changed

6 files changed

+22
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,6 @@
1212
- Fixed: [#5452](https://github.com/ethereum/aleth/pull/5452) Correctly handle Discovery messages when the peer changes public key.
1313
- Fixed: [#5519](https://github.com/ethereum/aleth/pull/5519) Correctly handle Discovery messages with known public key but unknown endpoint.
1414
- 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.
15+
- Added: [#5526](https://github.com/ethereum/aleth/pull/5526) Improved logging when loading chain config json containing syntax error.
1516

1617
[1.6.0]: https://github.com/ethereum/aleth/compare/v1.6.0-alpha.1...master

aleth/main.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -687,9 +687,10 @@ int main(int argc, char** argv)
687687
}
688688
catch (...)
689689
{
690-
cerr << "provided configuration is not well formatted\n";
691-
cerr << "sample: \n" << genesisInfo(eth::Network::MainNetworkTest) << "\n";
692-
return AlethErrors::Success;
690+
cerr << "provided configuration is not well-formatted\n";
691+
cerr << "well-formatted sample: \n"
692+
<< genesisInfo(eth::Network::MainNetworkTest) << "\n";
693+
return AlethErrors::ConfigFileInvalid;
693694
}
694695
}
695696

libdevcore/Exceptions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ DEV_SIMPLE_EXCEPTION(FailedInvariant);
7070
DEV_SIMPLE_EXCEPTION(ValueTooLarge);
7171
DEV_SIMPLE_EXCEPTION(UnknownField);
7272
DEV_SIMPLE_EXCEPTION(MissingField);
73+
DEV_SIMPLE_EXCEPTION(SyntaxError);
7374
DEV_SIMPLE_EXCEPTION(WrongFieldType);
7475
DEV_SIMPLE_EXCEPTION(InterfaceNotSupported);
7576
DEV_SIMPLE_EXCEPTION(ExternalFunctionFailure);

libethcore/Common.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ enum AlethErrors
226226
UnknownArgument,
227227
UnknownMiningOption,
228228
ConfigFileEmptyOrNotFound,
229+
ConfigFileInvalid,
229230
UnknownNetworkType,
230231
BadNetworkIdOption,
231232
BadConfigOption,

libethereum/ChainParams.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,20 @@ ChainParams ChainParams::loadConfig(
5959
{
6060
ChainParams cp(*this);
6161
js::mValue val;
62-
js::read_string_or_throw(_json, val);
62+
63+
try
64+
{
65+
js::read_string_or_throw(_json, val);
66+
}
67+
catch (js::Error_position const& error)
68+
{
69+
std::string const comment = "json parsing error detected on line " +
70+
std::to_string(error.line_) + " in column " +
71+
std::to_string(error.column_) + ": " + error.reason_;
72+
std::cerr << comment << "\n";
73+
BOOST_THROW_EXCEPTION(SyntaxError() << errinfo_comment(comment));
74+
}
75+
6376
js::mObject obj = val.get_obj();
6477

6578
validateConfigJson(obj);

test/unittests/libethereum/BlockChain.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ BOOST_AUTO_TEST_CASE(invalidJsonThrows)
408408
{
409409
h256 emptyStateRoot;
410410
/* Below, a comma is missing between fields. */
411-
BOOST_CHECK_THROW(ChainParams("{ \"sealEngine\" : \"unknown\" \"accountStartNonce\" : \"3\" }", emptyStateRoot), json_spirit::Error_position);
411+
BOOST_CHECK_THROW(ChainParams("{ \"sealEngine\" : \"unknown\" \"accountStartNonce\" : \"3\" }", emptyStateRoot), SyntaxError);
412412
}
413413

414414
BOOST_AUTO_TEST_CASE(unknownFieldThrows)

0 commit comments

Comments
 (0)