summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorNiko Savola <nikomsavola@gmail.com>2026-04-30 00:04:28 +0300
committerGitHub <noreply@github.com>2026-04-29 22:04:28 +0100
commit6bd15b948f1b266820c286c8f41fa7b4c2a12399 (patch)
tree9bf1dc85935dc7c5560dff180a3d70f4818bc4c4 /src/main.cpp
parent9ee5ff1f7181cc5fa575f1702802ccb78c21ba12 (diff)
main: improve error reporting during initialization in main.cpp (#14181)
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 566a2544..faf78083 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -100,14 +100,15 @@ int main(int argc, char** argv) {
return 1;
}
+ const auto FD_STR = *std::next(it);
try {
- socketFd = std::stoi(*std::next(it));
+ socketFd = std::stoi(FD_STR);
// check if socketFd is a valid file descriptor
if (fcntl(socketFd, F_GETFD) == -1)
- throw std::exception();
- } catch (...) {
- std::println(stderr, "[ ERROR ] Invalid Wayland FD!");
+ throw std::runtime_error("invalid or closed file descriptor");
+ } catch (const std::exception& e) {
+ std::println(stderr, "[ ERROR ] (main.cpp:{}) | Invalid Wayland FD '{}': {}!", __LINE__, FD_STR, e.what());
help();
return 1;
@@ -123,13 +124,14 @@ int main(int argc, char** argv) {
configPath = *std::next(it);
try {
- configPath = std::filesystem::canonical(configPath);
+ const auto ABS_PATH = std::filesystem::canonical(configPath);
- if (!std::filesystem::is_regular_file(configPath)) {
- throw std::exception();
+ if (!std::filesystem::is_regular_file(ABS_PATH)) {
+ throw std::runtime_error("not a regular file");
}
- } catch (...) {
- std::println(stderr, "[ ERROR ] Config file '{}' doesn't exist!", configPath);
+ configPath = ABS_PATH;
+ } catch (const std::exception& e) {
+ std::println(stderr, "[ ERROR ] (main.cpp:{}) | Config file '{}' is invalid: {}!", __LINE__, configPath, e.what());
help();
return 1;
@@ -165,11 +167,12 @@ int main(int argc, char** argv) {
return 1;
}
+ const auto WATCHDOG_STR = *std::next(it);
try {
- watchdogFd = std::stoi(*std::next(it));
+ watchdogFd = std::stoi(WATCHDOG_STR);
it++;
- } catch (...) {
- std::println(stderr, "[ ERROR ] Invalid fd for watchdog fd");
+ } catch (const std::exception& e) {
+ std::println(stderr, "[ ERROR ] (main.cpp:{}) | Invalid watchdog FD '{}': {}!", __LINE__, WATCHDOG_STR, e.what());
help();
return 1;
}