Skip to content

[solc] Exit code 2 for exceptions. #13633

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

Merged
merged 1 commit into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ 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.
* Language Server: Add basic document hover support.


Bugfixes:
* Solidity Upgrade Tool ``solidity-upgrade``: Fix the tool returning success code on uncaught exceptions.


### 0.8.17 (2022-09-08)
Expand Down
22 changes: 5 additions & 17 deletions solc/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 4 additions & 4 deletions test/tools/isoltest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
8 changes: 6 additions & 2 deletions tools/solidityUpgrade/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
44 changes: 5 additions & 39 deletions tools/yulPhaser/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<boost::throw_function>(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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any particular reason why we're not using using namespace std here, and more importantly, should we open a separate issue to address, or do it in this PR? Or do we want to just leave it as is? @cameel, I understand you've done most of the work on the phaser, so I guess it's up to you.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, if we have two consecutive stream writes, it would make more sense to append a newline, i.e. cerr << "bla bla" << "\n" and only endl in the last write, as there's no need to flush the stream every single time. We seem to follow this pattern everywhere though, so this PR is probably not the best place to fix it.

std::cerr << boost::current_exception_diagnostic_information() << std::endl;
return 2;
}
}