Skip to content

Commit 9f1857c

Browse files
authored
Fix core dump in chromobius by adding try-catch to main.cc (#39)
Currently, if one runs `chromobius` without any arguments, it prints the help text but also produces a core dump. This happens because the end of `src/chromobius/commands/main_all.cc` has ```cpp throw std::invalid_argument(ss.str()); ``` and this is not caught by `src/main.cc`. This commit adds a `try`-`catch` to `src/main.cc` to catch the exception and exit with a failure code. (This behavior is similar to what `main.perf.cc` does to exit with an error.)
1 parent d3561ce commit 9f1857c

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/main.cc

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
#include <iostream>
16+
#include <stdexcept>
17+
1518
#include "chromobius/commands/main_all.h"
1619

17-
int main(int argc, const char **argv) {
18-
return chromobius::main(argc, argv);
20+
int main(int argc, const char** argv) {
21+
try {
22+
return chromobius::main(argc, argv);
23+
} catch (const std::invalid_argument& ex) {
24+
std::cerr << ex.what() << std::endl;
25+
exit(EXIT_FAILURE);
26+
}
1927
}

0 commit comments

Comments
 (0)