-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cleanly report invalid [server] settings (RIPD-1562) #2305
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -893,19 +893,19 @@ to_Port(ParsedPort const& parsed, std::ostream& log) | |
|
||
if (! parsed.ip) | ||
{ | ||
log << "Missing 'ip' in [" << p.name << "]\n"; | ||
log << "Missing 'ip' in [" << p.name << "]"; | ||
Throw<std::exception> (); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Food for thought: why not do something like: Throwstd::runtime_exception("Missing 'ip' in [" + p.name + "]"); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @miguelportilla suggested a similar change. I had gone down that route (along with eliminating the exceptions altogether), but it was starting to touch more code than I was comfortable with for this targeted change. I wasn't sure if some callers wanted to distinguish logging from exception handling. |
||
} | ||
p.ip = *parsed.ip; | ||
|
||
if (! parsed.port) | ||
{ | ||
log << "Missing 'port' in [" << p.name << "]\n"; | ||
log << "Missing 'port' in [" << p.name << "]"; | ||
Throw<std::exception> (); | ||
} | ||
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> (); | ||
} | ||
p.port = *parsed.port; | ||
|
@@ -916,7 +916,7 @@ to_Port(ParsedPort const& parsed, std::ostream& log) | |
|
||
if (parsed.protocol.empty()) | ||
{ | ||
log << "Missing 'protocol' in [" << p.name << "]\n"; | ||
log << "Missing 'protocol' in [" << p.name << "]"; | ||
Throw<std::exception> (); | ||
} | ||
p.protocol = parsed.protocol; | ||
|
@@ -947,7 +947,7 @@ parse_Ports ( | |
if (! config.exists("server")) | ||
{ | ||
log << | ||
"Required section [server] is missing\n"; | ||
"Required section [server] is missing"; | ||
Throw<std::exception> (); | ||
} | ||
|
||
|
@@ -961,7 +961,7 @@ parse_Ports ( | |
if (! config.exists(name)) | ||
{ | ||
log << | ||
"Missing section: [" << name << "]\n"; | ||
"Missing section: [" << name << "]"; | ||
Throw<std::exception> (); | ||
} | ||
ParsedPort parsed = common; | ||
|
@@ -997,12 +997,12 @@ parse_Ports ( | |
|
||
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> (); | ||
} | ||
|
||
if (count == 0) | ||
log << "Warning: No peer protocol configured\n"; | ||
log << "Warning: No peer protocol configured"; | ||
} | ||
|
||
return result; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be useful to log the exception message if one exists. Even if the current code is unlikely to produce one now, it might catch a new message in the future.
Just an idea- If the exception message was logged here, throws in
to_Port
orpopulate
etc.. could include the message instead of logging and throwing which seems kinda kludgy.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good suggestions. I went with printing the message if one exists to keep a limited scope of this PR.