Skip to content

Commit ec40cc9

Browse files
authored
fix: Shutdown LogService after exceptions are printed (#2464)
1 parent 3681ef4 commit ec40cc9

File tree

1 file changed

+22
-13
lines changed

1 file changed

+22
-13
lines changed

src/main/Main.cpp

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,16 @@
3434

3535
using namespace util::config;
3636

37+
[[nodiscard]]
3738
int
38-
main(int argc, char const* argv[])
39-
try {
40-
util::setTerminationHandler();
41-
util::ScopeGuard const loggerShutdownGuard{[]() { util::LogService::shutdown(); }};
42-
39+
runApp(int argc, char const* argv[])
40+
{
4341
auto const action = app::CliArgs::parse(argc, argv);
4442
return action.apply(
4543
[](app::CliArgs::Action::Exit const& exit) { return exit.exitCode; },
4644
[](app::CliArgs::Action::VerifyConfig const& verify) {
4745
if (app::parseConfig(verify.configPath)) {
48-
std::cout << "Config " << verify.configPath << " is correct"
49-
<< "\n";
46+
std::cout << "Config " << verify.configPath << " is correct" << "\n";
5047
return EXIT_SUCCESS;
5148
}
5249
return EXIT_FAILURE;
@@ -76,10 +73,22 @@ try {
7673
return migrator.run();
7774
}
7875
);
79-
} catch (std::exception const& e) {
80-
LOG(util::LogService::fatal()) << "Exit on exception: " << e.what();
81-
return EXIT_FAILURE;
82-
} catch (...) {
83-
LOG(util::LogService::fatal()) << "Exit on exception: unknown";
84-
return EXIT_FAILURE;
76+
}
77+
78+
int
79+
main(int argc, char const* argv[])
80+
{
81+
util::setTerminationHandler();
82+
83+
util::ScopeGuard const loggerShutdownGuard{[] { util::LogService::shutdown(); }};
84+
85+
try {
86+
return runApp(argc, argv);
87+
} catch (std::exception const& e) {
88+
LOG(util::LogService::fatal()) << "Exit on exception: " << e.what();
89+
return EXIT_FAILURE;
90+
} catch (...) {
91+
LOG(util::LogService::fatal()) << "Exit on exception: unknown";
92+
return EXIT_FAILURE;
93+
}
8594
}

0 commit comments

Comments
 (0)