-
Notifications
You must be signed in to change notification settings - Fork 0
Implementation of invalid user input exception #5
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
Implementation of invalid user input exception #5
Conversation
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.
LGTM for the most part
src/cbmc/cbmc_solvers.cpp
Outdated
throw invalid_user_input_exceptiont( | ||
"Reason: sorry, this solver does not support incremental solving", | ||
"--incremental-check", | ||
""); |
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.
This is quite a big improvement over the previous version that didn't tell you what option it didn't like, 👍
src/util/exception_utils.h
Outdated
std::string res; | ||
res += "\nInvalid User Input Exception\n"; | ||
res += "Option: " + option + "\n"; | ||
res += reason; |
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.
I think it's fine to have the "Reason: "
part here, I just didn't like forcing the form of the part after the reason.
Sorry for being unclear with this
4ffe61a
to
5a1d8b6
Compare
src/cbmc/bv_cbmc.cpp
Outdated
error() << "waitfor expected to have four operands" << eom; | ||
throw 0; | ||
} | ||
PRECONDITION(expr.operands().size() != 4); |
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.
We could use DATA_INVARIANT
here which is for checking whether goto programs, exprts, etc. are well-formed. Then we can also keep the error message.
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.
I won't implement this. It's easily implementable, but the error message is just redundant IMO. It doesn't convey any information that the precondition expression doesn't convey already. It just duplicates semantic information about the behaviour of the code.
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.
Hm the error message had the additional information that expr
is a wait-for expression (i.e., expr.id()
is "waitfor"
). From the condition we only see that it is some expression with four operands.
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 spot, didn't notice that. I guess I can rewrite that a little bit as well.
src/cbmc/show_vcc.cpp
Outdated
@@ -143,7 +144,8 @@ void bmct::show_vcc() | |||
{ | |||
of.open(filename); | |||
if(!of) | |||
throw "failed to open file "+filename; | |||
throw invalid_user_input_exceptiont( | |||
"Failed to open suggested file", "--outfile", ""); |
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.
We can drop "suggested", and append the filename to the first argument.
src/util/exception_utils.h
Outdated
invalid_user_input_exceptiont( | ||
std::string reason, | ||
std::string option, | ||
std::string correct_input) |
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.
Can we have an empty string default argument for correct_input
?
src/util/exception_utils.h
Outdated
res += "Option: " + option + "\n"; | ||
res += "Reason: " + reason; | ||
// Print an optional correct usage message assuming correct input parameters have been passed | ||
correct_input.empty() ? "\n" : res += " Try: " + correct_input + "\n"; |
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.
I think we need to add a newline before " Try"
.
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.
I'd rather it be kept on the same line.
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.
Should we add a separator character then? Maybe a comma.
src/cbmc/cbmc_main.cpp
Outdated
@@ -52,4 +58,9 @@ int main(int argc, const char **argv) | |||
#endif | |||
|
|||
return res; | |||
} | |||
catch(invalid_user_input_exceptiont &e) |
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.
Currently if an exception is caught here the program still exits with a zero exit code. We should change this to exit with an error code.
I think we can also move the exception catching code to parse_options_baset::main()
(wrapping the call to doit()
). Then the tools that inherit from it don't need to repeat the exception handlers.
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.
This is very interesting. It's a great suggestion, but this needs a little bit thinking about how to properly implement this (I haven't thought it through yet, might be easier than I realise)
5a1d8b6
to
b8bb108
Compare
@hannes-steffenhagen-diffblue @danpoe Can I request a new review from both of you? Made some substantial changes on where we handle exceptions in the latest commit. |
b8bb108
to
c952a8a
Compare
src/cbmc/cbmc_main.cpp
Outdated
@@ -25,6 +25,10 @@ Author: Daniel Kroening, [email protected] | |||
#include <iostream> | |||
#endif | |||
|
|||
#include <iostream> | |||
|
|||
#include <util/exception_utils.h> |
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.
I think those two includes are now not needed anymore.
src/cbmc/show_vcc.cpp
Outdated
@@ -143,7 +144,8 @@ void bmct::show_vcc() | |||
{ | |||
of.open(filename); | |||
if(!of) | |||
throw "failed to open file "+filename; | |||
throw invalid_user_input_exceptiont( | |||
"Failed to open file" + filename, "--outfile"); |
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.
... file"
-> ...file "
c952a8a
to
6f3f888
Compare
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.
Looks good to me!
@@ -143,7 +144,8 @@ void bmct::show_vcc() | |||
{ | |||
of.open(filename); | |||
if(!of) | |||
throw "failed to open file "+filename; | |||
throw invalid_user_input_exceptiont( | |||
"Failed to open file: " + filename, "--outfile"); |
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.
Thinking about it, I don't really like this being an invalid user input exception (I suppose you can justify it being subject to user input as they control the filename, but technically whether or not we're able to open the file isn't necessarily up to the user).
Not a blocker for sure, but in general I'd have a preference for IO related exceptions to have their own place.
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.
Still looks OK to me
6f3f888
to
0248d40
Compare
This PR contains an implementation of an erroneous user input exception, and changes the unstructured
throw 0
s in thecbmc/
folder into structured exceptions and preconditions/invariants.