mirror of
https://github.com/hyprwm/Hyprland
synced 2026-05-08 04:58:02 +02:00
main: improve error reporting during initialization in main.cpp (#14181)
This commit is contained in:
parent
9ee5ff1f71
commit
6bd15b948f
1 changed files with 15 additions and 12 deletions
27
src/main.cpp
27
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue