From 5b9096a381000e9cadcb0eb2ad4f751819cd374d Mon Sep 17 00:00:00 2001 From: Alexander Arlt Date: Tue, 18 Oct 2022 14:43:41 -0500 Subject: [PATCH] [solc] Exit code 2 for exceptions. --- Changelog.md | 2 ++ solc/main.cpp | 22 ++++------------- test/tools/isoltest.cpp | 8 +++---- tools/solidityUpgrade/main.cpp | 8 +++++-- tools/yulPhaser/main.cpp | 44 ++++------------------------------ 5 files changed, 22 insertions(+), 62 deletions(-) diff --git a/Changelog.md b/Changelog.md index e6fea266e..68c755734 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,6 +4,7 @@ Language Features: Compiler Features: +* Commandline Interface: Return exit code ``2`` on uncaught exceptions. * Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode. * Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode. * Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string. @@ -11,6 +12,7 @@ Compiler Features: Bugfixes: + * Solidity Upgrade Tool ``solidity-upgrade``: Fix the tool returning success code on uncaught exceptions. ### 0.8.17 (2022-09-08) diff --git a/solc/main.cpp b/solc/main.cpp index 50a6a8fc5..a6fa5015b 100644 --- a/solc/main.cpp +++ b/solc/main.cpp @@ -44,36 +44,24 @@ int main(int argc, char** argv) { cerr << "SMT logic error:" << endl; cerr << boost::diagnostic_information(_exception); - return 1; + return 2; } catch (langutil::UnimplementedFeatureError const& _exception) { cerr << "Unimplemented feature:" << endl; cerr << boost::diagnostic_information(_exception); - return 1; + return 2; } catch (langutil::InternalCompilerError const& _exception) { cerr << "Internal compiler error:" << endl; cerr << boost::diagnostic_information(_exception); - return 1; - } - catch (boost::exception const& _exception) - { - cerr << "Uncaught exception:" << endl; - cerr << boost::diagnostic_information(_exception) << endl; - return 1; - } - catch (std::exception const& _exception) - { - cerr << "Uncaught exception:" << endl; - cerr << boost::diagnostic_information(_exception) << endl; - return 1; + return 2; } catch (...) { - cerr << "Uncaught exception" << endl; + cerr << "Uncaught exception:" << endl; cerr << boost::current_exception_diagnostic_information() << endl; - return 1; + return 2; } } diff --git a/test/tools/isoltest.cpp b/test/tools/isoltest.cpp index cb7ab1eb5..cf1588b44 100644 --- a/test/tools/isoltest.cpp +++ b/test/tools/isoltest.cpp @@ -502,22 +502,22 @@ int main(int argc, char const *argv[]) catch (boost::program_options::error const& exception) { cerr << exception.what() << endl; - return EXIT_FAILURE; + return 2; } catch (std::runtime_error const& exception) { cerr << exception.what() << endl; - return EXIT_FAILURE; + return 2; } catch (solidity::test::ConfigException const& exception) { cerr << exception.what() << endl; - return EXIT_FAILURE; + return 2; } catch (...) { cerr << "Unhandled exception caught." << endl; cerr << boost::current_exception_diagnostic_information() << endl; - return EXIT_FAILURE; + return 2; } } diff --git a/tools/solidityUpgrade/main.cpp b/tools/solidityUpgrade/main.cpp index 55ed0118c..5a6962661 100644 --- a/tools/solidityUpgrade/main.cpp +++ b/tools/solidityUpgrade/main.cpp @@ -84,11 +84,15 @@ int main(int argc, char** argv) } catch (boost::exception const& _exception) { - cerr << "Exception while processing input: " << boost::diagnostic_information(_exception) << endl; + cerr << "Exception while processing input:" << endl; + cerr << boost::diagnostic_information(_exception) << endl; + return 2; } catch (...) { - cerr << "Unknown exception while processing input: " << boost::current_exception_diagnostic_information() << endl; + cerr << "Uncaught exception while processing input:" << endl; + cerr << boost::current_exception_diagnostic_information() << endl; + return 2; } return 0; diff --git a/tools/yulPhaser/main.cpp b/tools/yulPhaser/main.cpp index 1ec936dd4..21502b525 100644 --- a/tools/yulPhaser/main.cpp +++ b/tools/yulPhaser/main.cpp @@ -36,7 +36,7 @@ int main(int argc, char** argv) std::cerr << std::endl; std::cerr << "ERROR: " << exception.what() << std::endl; - return 1; + return 2; } catch (solidity::phaser::BadInput const& exception) { @@ -45,46 +45,12 @@ int main(int argc, char** argv) std::cerr << std::endl; std::cerr << "ERROR: " << exception.what() << std::endl; - return 1; - } - catch (solidity::util::Exception const& exception) - { - // Something's seriously wrong. Probably a bug in the program or a missing handler (which - // is really also a bug). The exception should have been handled gracefully by this point - // if it's something that can happen in normal usage. E.g. an error in the input or a - // failure of some part of the system that's outside of control of the application (disk, - // network, etc.). The bug should be reported and investigated so our job here is just to - // provide as much useful information about it as possible. - - std::cerr << std::endl; - std::cerr << "UNCAUGHT EXCEPTION!" << std::endl; - - // We can print some useful diagnostic info for this particular exception type. - std::cerr << "Location: " << exception.lineInfo() << std::endl; - - char const* const* function = boost::get_error_info(exception); - if (function != nullptr) - std::cerr << "Function: " << *function << std::endl; - - // Let it crash. The terminate() will print some more stuff useful for debugging like - // what() and the actual exception type. - throw; - } - catch (std::exception const&) - { - // Again, probably a bug but this time it's just plain std::exception so there's no point - // in doing anything special. terminate() will do an adequate job. - std::cerr << std::endl; - std::cerr << "UNCAUGHT EXCEPTION!" << std::endl; - throw; + return 2; } catch (...) { - // Some people don't believe these exist. - // I have no idea what this is and it's flying towards me so technically speaking it's an - // unidentified flying object. - std::cerr << std::endl; - std::cerr << "UFO SPOTTED!" << std::endl; - throw; + std::cerr << "Uncaught exception:" << std::endl; + std::cerr << boost::current_exception_diagnostic_information() << std::endl; + return 2; } }