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

Commit 8fbe95d

Browse files
committed
Log json exception details on chain config error
Also return new error code AlethErrors::ConfigFileInvalid
1 parent ae042a3 commit 8fbe95d

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

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);

0 commit comments

Comments
 (0)