Skip to content

Commit

Permalink
config: produce error instead fs::exists exceptions (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexec committed Jun 9, 2024
1 parent 374d6e2 commit f4abf59
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/config/ConfigManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit f4abf59

Please sign in to comment.