Skip to content

Commit 05217fa

Browse files
authored
Merge pull request #13633 from ethereum/solc-return-codes
[solc] Exit code 2 for exceptions.
2 parents bbaf8a4 + 5b9096a commit 05217fa

File tree

5 files changed

+22
-62
lines changed

5 files changed

+22
-62
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ Language Features:
44

55

66
Compiler Features:
7+
* Commandline Interface: Return exit code ``2`` on uncaught exceptions.
78
* Commandline Interface: Add `--no-cbor-metadata` that skips CBOR metadata from getting appended at the end of the bytecode.
89
* Standard JSON: Add a boolean field `settings.metadata.appendCBOR` that skips CBOR metadata from getting appended at the end of the bytecode.
910
* Yul Optimizer: Allow replacing the previously hard-coded cleanup sequence by specifying custom steps after a colon delimiter (``:``) in the sequence string.
1011
* Language Server: Add basic document hover support.
1112

1213

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

1517

1618
### 0.8.17 (2022-09-08)

solc/main.cpp

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -44,36 +44,24 @@ int main(int argc, char** argv)
4444
{
4545
cerr << "SMT logic error:" << endl;
4646
cerr << boost::diagnostic_information(_exception);
47-
return 1;
47+
return 2;
4848
}
4949
catch (langutil::UnimplementedFeatureError const& _exception)
5050
{
5151
cerr << "Unimplemented feature:" << endl;
5252
cerr << boost::diagnostic_information(_exception);
53-
return 1;
53+
return 2;
5454
}
5555
catch (langutil::InternalCompilerError const& _exception)
5656
{
5757
cerr << "Internal compiler error:" << endl;
5858
cerr << boost::diagnostic_information(_exception);
59-
return 1;
60-
}
61-
catch (boost::exception const& _exception)
62-
{
63-
cerr << "Uncaught exception:" << endl;
64-
cerr << boost::diagnostic_information(_exception) << endl;
65-
return 1;
66-
}
67-
catch (std::exception const& _exception)
68-
{
69-
cerr << "Uncaught exception:" << endl;
70-
cerr << boost::diagnostic_information(_exception) << endl;
71-
return 1;
59+
return 2;
7260
}
7361
catch (...)
7462
{
75-
cerr << "Uncaught exception" << endl;
63+
cerr << "Uncaught exception:" << endl;
7664
cerr << boost::current_exception_diagnostic_information() << endl;
77-
return 1;
65+
return 2;
7866
}
7967
}

test/tools/isoltest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,22 +502,22 @@ int main(int argc, char const *argv[])
502502
catch (boost::program_options::error const& exception)
503503
{
504504
cerr << exception.what() << endl;
505-
return EXIT_FAILURE;
505+
return 2;
506506
}
507507
catch (std::runtime_error const& exception)
508508
{
509509
cerr << exception.what() << endl;
510-
return EXIT_FAILURE;
510+
return 2;
511511
}
512512
catch (solidity::test::ConfigException const& exception)
513513
{
514514
cerr << exception.what() << endl;
515-
return EXIT_FAILURE;
515+
return 2;
516516
}
517517
catch (...)
518518
{
519519
cerr << "Unhandled exception caught." << endl;
520520
cerr << boost::current_exception_diagnostic_information() << endl;
521-
return EXIT_FAILURE;
521+
return 2;
522522
}
523523
}

tools/solidityUpgrade/main.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,15 @@ int main(int argc, char** argv)
8484
}
8585
catch (boost::exception const& _exception)
8686
{
87-
cerr << "Exception while processing input: " << boost::diagnostic_information(_exception) << endl;
87+
cerr << "Exception while processing input:" << endl;
88+
cerr << boost::diagnostic_information(_exception) << endl;
89+
return 2;
8890
}
8991
catch (...)
9092
{
91-
cerr << "Unknown exception while processing input: " << boost::current_exception_diagnostic_information() << endl;
93+
cerr << "Uncaught exception while processing input:" << endl;
94+
cerr << boost::current_exception_diagnostic_information() << endl;
95+
return 2;
9296
}
9397

9498
return 0;

tools/yulPhaser/main.cpp

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
3636

3737
std::cerr << std::endl;
3838
std::cerr << "ERROR: " << exception.what() << std::endl;
39-
return 1;
39+
return 2;
4040
}
4141
catch (solidity::phaser::BadInput const& exception)
4242
{
@@ -45,46 +45,12 @@ int main(int argc, char** argv)
4545

4646
std::cerr << std::endl;
4747
std::cerr << "ERROR: " << exception.what() << std::endl;
48-
return 1;
49-
}
50-
catch (solidity::util::Exception const& exception)
51-
{
52-
// Something's seriously wrong. Probably a bug in the program or a missing handler (which
53-
// is really also a bug). The exception should have been handled gracefully by this point
54-
// if it's something that can happen in normal usage. E.g. an error in the input or a
55-
// failure of some part of the system that's outside of control of the application (disk,
56-
// network, etc.). The bug should be reported and investigated so our job here is just to
57-
// provide as much useful information about it as possible.
58-
59-
std::cerr << std::endl;
60-
std::cerr << "UNCAUGHT EXCEPTION!" << std::endl;
61-
62-
// We can print some useful diagnostic info for this particular exception type.
63-
std::cerr << "Location: " << exception.lineInfo() << std::endl;
64-
65-
char const* const* function = boost::get_error_info<boost::throw_function>(exception);
66-
if (function != nullptr)
67-
std::cerr << "Function: " << *function << std::endl;
68-
69-
// Let it crash. The terminate() will print some more stuff useful for debugging like
70-
// what() and the actual exception type.
71-
throw;
72-
}
73-
catch (std::exception const&)
74-
{
75-
// Again, probably a bug but this time it's just plain std::exception so there's no point
76-
// in doing anything special. terminate() will do an adequate job.
77-
std::cerr << std::endl;
78-
std::cerr << "UNCAUGHT EXCEPTION!" << std::endl;
79-
throw;
48+
return 2;
8049
}
8150
catch (...)
8251
{
83-
// Some people don't believe these exist.
84-
// I have no idea what this is and it's flying towards me so technically speaking it's an
85-
// unidentified flying object.
86-
std::cerr << std::endl;
87-
std::cerr << "UFO SPOTTED!" << std::endl;
88-
throw;
52+
std::cerr << "Uncaught exception:" << std::endl;
53+
std::cerr << boost::current_exception_diagnostic_information() << std::endl;
54+
return 2;
8955
}
9056
}

0 commit comments

Comments
 (0)