-
Notifications
You must be signed in to change notification settings - Fork 273
Cleanup error handling of cbmc/ folder #2703
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
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ int main(int argc, const char **argv) | |
#endif | ||
cbmc_parse_optionst parse_options(argc, argv); | ||
|
||
int res=parse_options.main(); | ||
int res = parse_options.main(); | ||
|
||
#ifdef IREP_HASH_STATS | ||
std::cout << "IREP_HASH_CNT=" << irep_hash_cnt << '\n'; | ||
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. indentation |
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Exception helper utilities | ||
|
||
Author: Fotis Koutoulakis, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#include "exception_utils.h" | ||
|
||
std::string invalid_user_input_exceptiont::what() const noexcept | ||
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. Ideally, there should also be a version hat can serialise into json and XML in a more structure way (in a future PR). |
||
{ | ||
std::string res; | ||
res += "\nInvalid User Input\n"; | ||
res += "Option: " + option + "\n"; | ||
res += "Reason: " + reason; | ||
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. Wishlist: please add a test for this, i.e., intentionally use CBMC with incorrect options. 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. Do you need this as part of this PR, or can it go in as part of a follow up PR for example? 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. Up to you, as long as it happens at some point :-) 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. We plan to make some further improvements to user error handling, so we'll definitely be adding suitable test cases as part of that work, so I'd be happy for this PR to go in, with tests following as part of the later improvements. |
||
// Print an optional correct usage message assuming correct input parameters have been passed | ||
res += correct_input + "\n"; | ||
return res; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/*******************************************************************\ | ||
|
||
Module: Exception helper utilities | ||
|
||
Author: Fotis Koutoulakis, [email protected] | ||
|
||
\*******************************************************************/ | ||
|
||
#ifndef CPROVER_UTIL_EXCEPTION_UTILS_H | ||
#define CPROVER_UTIL_EXCEPTION_UTILS_H | ||
|
||
#include <string> | ||
|
||
class invalid_user_input_exceptiont | ||
{ | ||
std::string reason; | ||
std::string option; | ||
std::string correct_input; | ||
|
||
public: | ||
invalid_user_input_exceptiont( | ||
std::string reason, | ||
std::string option, | ||
std::string correct_input = "") | ||
: reason(reason), option(option), correct_input(correct_input) | ||
{ | ||
} | ||
|
||
std::string what() const noexcept; | ||
}; | ||
|
||
#endif // CPROVER_UTIL_EXCEPTION_UTILS_H |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,8 @@ Author: Daniel Kroening, [email protected] | |
#endif | ||
|
||
#include "cmdline.h" | ||
#include "exception_utils.h" | ||
#include "exit_codes.h" | ||
#include "signal_catcher.h" | ||
|
||
parse_options_baset::parse_options_baset( | ||
|
@@ -47,23 +49,34 @@ void parse_options_baset::unknown_option_msg() | |
|
||
int parse_options_baset::main() | ||
{ | ||
if(parse_result) | ||
// catch all exceptions here so that this code is not duplicated | ||
// for each tool | ||
try | ||
{ | ||
usage_error(); | ||
unknown_option_msg(); | ||
return EX_USAGE; | ||
if(parse_result) | ||
{ | ||
usage_error(); | ||
unknown_option_msg(); | ||
return EX_USAGE; | ||
} | ||
|
||
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help")) | ||
{ | ||
help(); | ||
return EX_OK; | ||
} | ||
|
||
// install signal catcher | ||
install_signal_catcher(); | ||
|
||
return doit(); | ||
} | ||
|
||
if(cmdline.isset('?') || cmdline.isset('h') || cmdline.isset("help")) | ||
catch(invalid_user_input_exceptiont &e) | ||
{ | ||
help(); | ||
return EX_OK; | ||
std::cerr << e.what() << "\n"; | ||
return CPROVER_EXIT_USAGE_ERROR; | ||
} | ||
|
||
// install signal catcher | ||
install_signal_catcher(); | ||
|
||
return doit(); | ||
return CPROVER_EXIT_SUCCESS; | ||
} | ||
|
||
std::string | ||
|
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.
Unnecessary change?