Cleanly report invalid [server] settings (RIPD-1562)

This commit is contained in:
Brad Chase
2017-12-18 16:54:43 -05:00
committed by Nikolaos D. Bougalis
parent 20cdb4dca0
commit edf58820cf
3 changed files with 34 additions and 21 deletions

View File

@@ -61,6 +61,7 @@
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <iostream> #include <iostream>
#include <cstring>
namespace ripple { namespace ripple {
@@ -1225,11 +1226,23 @@ bool ApplicationImp::setup()
} }
{ {
auto setup = setup_ServerHandler( try
*config_, {
beast::logstream { m_journal.error() }); auto setup = setup_ServerHandler(
setup.makeContexts(); *config_, beast::logstream{m_journal.error()});
serverHandler_->setup (setup, m_journal); setup.makeContexts();
serverHandler_->setup(setup, m_journal);
}
catch (std::exception const& e)
{
if (auto stream = m_journal.fatal())
{
stream << "Unable to setup server handler";
if(std::strlen(e.what()) > 0)
stream << ": " << e.what();
}
return false;
}
} }
// Begin connecting to network. // Begin connecting to network.

View File

@@ -893,19 +893,19 @@ to_Port(ParsedPort const& parsed, std::ostream& log)
if (! parsed.ip) if (! parsed.ip)
{ {
log << "Missing 'ip' in [" << p.name << "]\n"; log << "Missing 'ip' in [" << p.name << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
p.ip = *parsed.ip; p.ip = *parsed.ip;
if (! parsed.port) if (! parsed.port)
{ {
log << "Missing 'port' in [" << p.name << "]\n"; log << "Missing 'port' in [" << p.name << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
else if (*parsed.port == 0) else if (*parsed.port == 0)
{ {
log << "Port " << *parsed.port << "in [" << p.name << "] is invalid\n"; log << "Port " << *parsed.port << "in [" << p.name << "] is invalid";
Throw<std::exception> (); Throw<std::exception> ();
} }
p.port = *parsed.port; p.port = *parsed.port;
@@ -916,7 +916,7 @@ to_Port(ParsedPort const& parsed, std::ostream& log)
if (parsed.protocol.empty()) if (parsed.protocol.empty())
{ {
log << "Missing 'protocol' in [" << p.name << "]\n"; log << "Missing 'protocol' in [" << p.name << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
p.protocol = parsed.protocol; p.protocol = parsed.protocol;
@@ -947,7 +947,7 @@ parse_Ports (
if (! config.exists("server")) if (! config.exists("server"))
{ {
log << log <<
"Required section [server] is missing\n"; "Required section [server] is missing";
Throw<std::exception> (); Throw<std::exception> ();
} }
@@ -961,7 +961,7 @@ parse_Ports (
if (! config.exists(name)) if (! config.exists(name))
{ {
log << log <<
"Missing section: [" << name << "]\n"; "Missing section: [" << name << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
ParsedPort parsed = common; ParsedPort parsed = common;
@@ -997,12 +997,12 @@ parse_Ports (
if (count > 1) if (count > 1)
{ {
log << "Error: More than one peer protocol configured in [server]\n"; log << "Error: More than one peer protocol configured in [server]";
Throw<std::exception> (); Throw<std::exception> ();
} }
if (count == 0) if (count == 0)
log << "Warning: No peer protocol configured\n"; log << "Warning: No peer protocol configured";
} }
return result; return result;

View File

@@ -87,7 +87,7 @@ populate (Section const& section, std::string const& field, std::ostream& log,
if (! addr.second) if (! addr.second)
{ {
log << "Invalid value '" << ip << "' for key '" << field << log << "Invalid value '" << ip << "' for key '" << field <<
"' in [" << section.name () << "]\n"; "' in [" << section.name () << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
@@ -97,7 +97,7 @@ populate (Section const& section, std::string const& field, std::ostream& log,
{ {
log << "0.0.0.0 not allowed'" << log << "0.0.0.0 not allowed'" <<
"' for key '" << field << "' in [" << "' for key '" << field << "' in [" <<
section.name () << "]\n"; section.name () << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
else else
@@ -110,7 +110,7 @@ populate (Section const& section, std::string const& field, std::ostream& log,
{ {
log << "IP specified along with 0.0.0.0 '" << ip << log << "IP specified along with 0.0.0.0 '" << ip <<
"' for key '" << field << "' in [" << "' for key '" << field << "' in [" <<
section.name () << "]\n"; section.name () << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
@@ -123,7 +123,7 @@ populate (Section const& section, std::string const& field, std::ostream& log,
) != admin_ip.end()) ) != admin_ip.end())
{ {
log << "IP specified for " << field << " is also for " << log << "IP specified for " << field << " is also for " <<
"admin: " << ip << " in [" << section.name() << "]\n"; "admin: " << ip << " in [" << section.name() << "]";
Throw<std::exception> (); Throw<std::exception> ();
} }
@@ -146,7 +146,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log)
catch (std::exception const&) catch (std::exception const&)
{ {
log << "Invalid value '" << result.first << log << "Invalid value '" << result.first <<
"' for key 'ip' in [" << section.name() << "]\n"; "' for key 'ip' in [" << section.name() << "]";
Rethrow(); Rethrow();
} }
} }
@@ -169,7 +169,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log)
{ {
log << log <<
"Invalid value '" << result.first << "' for key " << "Invalid value '" << result.first << "' for key " <<
"'port' in [" << section.name() << "]\n"; "'port' in [" << section.name() << "]";
Rethrow(); Rethrow();
} }
} }
@@ -199,7 +199,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log)
{ {
log << log <<
"Invalid value '" << lim << "' for key " << "Invalid value '" << lim << "' for key " <<
"'limit' in [" << section.name() << "]\n"; "'limit' in [" << section.name() << "]";
Rethrow(); Rethrow();
} }
} }
@@ -222,7 +222,7 @@ parse_Port (ParsedPort& port, Section const& section, std::ostream& log)
{ {
log << log <<
"Invalid value '" << result.first << "' for key " << "Invalid value '" << result.first << "' for key " <<
"'send_queue_limit' in [" << section.name() << "]\n"; "'send_queue_limit' in [" << section.name() << "]";
Rethrow(); Rethrow();
} }
} }