From f4abf5902f3f0c51d2aab8a521f7c1b1b08afd64 Mon Sep 17 00:00:00 2001 From: Mykola Perehudov Date: Sun, 9 Jun 2024 10:50:27 +0300 Subject: [PATCH] config: produce error instead fs::exists exceptions (#177) --- src/config/ConfigManager.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp index 6990ca6..86c3129 100644 --- a/src/config/ConfigManager.cpp +++ b/src/config/ConfigManager.cpp @@ -26,8 +26,10 @@ static Hyprlang::CParseResult handleWallpaper(const char* C, const char* V) { WALLPAPER = std::string(ENVHOME) + WALLPAPER.substr(1); } - if (!std::filesystem::exists(WALLPAPER)) { - result.setError("wallpaper failed (no such file)"); + std::error_code ec; + + if (!std::filesystem::exists(WALLPAPER, ec)) { + result.setError((std::string{"wallpaper failed ("} + (ec ? ec.message() : std::string{"no such file"}) + std::string{": "} + WALLPAPER + std::string{")"}).c_str()); return result; } @@ -67,9 +69,11 @@ static Hyprlang::CParseResult handlePreload(const char* C, const char* V) { WALLPAPER = std::string(ENVHOME) + WALLPAPER.substr(1); } - if (!std::filesystem::exists(WALLPAPER)) { + std::error_code ec; + + if (!std::filesystem::exists(WALLPAPER, ec)) { Hyprlang::CParseResult result; - result.setError((std::string{"no such file: "} + WALLPAPER).c_str()); + result.setError(((ec ? ec.message() : std::string{"no such file"}) + std::string{": "} + WALLPAPER).c_str()); return result; }