Skip to content

Commit 01e9c1f

Browse files
committed
config: refuse to start with a bad config
1 parent e441358 commit 01e9c1f

3 files changed

Lines changed: 11 additions & 7 deletions

File tree

src/config/ConfigManager.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ CConfigManager::CConfigManager(const std::string& configPath) :
4848
m_currentConfigPath = configPath.empty() ? getMainConfigPath() : configPath;
4949
}
5050

51-
void CConfigManager::init() {
51+
bool CConfigManager::init() {
5252
m_config.addConfigValue("splash", Hyprlang::INT{1});
5353
m_config.addConfigValue("splash_offset", Hyprlang::INT{20});
5454
m_config.addConfigValue("splash_opacity", Hyprlang::FLOAT{0.8});
@@ -64,10 +64,13 @@ void CConfigManager::init() {
6464

6565
auto result = m_config.parse();
6666

67-
if (result.error)
68-
g_logger->log(LOG_ERR, "Config has errors:\n{}\nProceeding ignoring faulty entries", result.getError());
67+
if (result.error) {
68+
g_logger->log(LOG_ERR, "Config has errors:\n{}", result.getError());
69+
return false;
70+
}
6971

7072
g_matcher->addStates(getSettings());
73+
return true;
7174
}
7275

7376
Hyprlang::CConfig* CConfigManager::hyprlang() {
@@ -117,10 +120,10 @@ static std::expected<std::vector<std::string>, std::string> getFullPath(const st
117120

118121
if (std::filesystem::is_directory(resolvedPath))
119122
for (const auto& entry : std::filesystem::directory_iterator(resolvedPath, std::filesystem::directory_options::skip_permission_denied)) {
120-
if (entry.is_regular_file() && isImage(entry.path()))
123+
if (entry.is_regular_file() && isImage(entry.path()))
121124
result.push_back(entry.path());
122125

123-
if (result.size() >= maxImagesCount)
126+
if (result.size() >= maxImagesCount)
124127
break;
125128
}
126129
else if (isImage(resolvedPath))

src/config/ConfigManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class CConfigManager {
2222

2323
constexpr static const uint32_t SETTING_INVALID = 0;
2424

25-
void init();
25+
bool init();
2626
Hyprlang::CConfig* hyprlang();
2727

2828
std::vector<SSetting> getSettings();

src/main.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ int main(int argc, const char** argv, const char** envp) {
3131
g_logger->log(LOG_DEBUG, "Welcome to hyprpaper!\nbuilt from commit {} ({})", GIT_COMMIT_HASH, GIT_COMMIT_MESSAGE);
3232

3333
g_config = makeUnique<CConfigManager>(std::string{parser.getString("config").value_or("")});
34-
g_config->init();
34+
if (!g_config->init())
35+
return 1;
3536

3637
g_ui = makeUnique<CUI>();
3738
g_ui->run();

0 commit comments

Comments
 (0)