mirror of
https://github.com/polybar/polybar.git
synced 2026-02-12 18:45:38 +00:00
config: Better error messages when opening files
If a config file is a directory, ifstream would just read it as an empty file without any errors. Failing early here is a good idea.
This commit is contained in:
committed by
Patrick Ziegler
parent
9d31b51a63
commit
75eb41f5ad
@ -1,8 +1,13 @@
|
||||
#include "components/config_parser.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cerrno>
|
||||
#include <cstring>
|
||||
#include <fstream>
|
||||
|
||||
#include "utils/file.hpp"
|
||||
#include "utils/string.hpp"
|
||||
|
||||
POLYBAR_NS
|
||||
|
||||
config_parser::config_parser(const logger& logger, string&& file, string&& bar)
|
||||
@ -89,6 +94,14 @@ void config_parser::parse_file(const string& file, file_list path) {
|
||||
throw application_error("include-file: Dependency cycle detected:\n" + path_str);
|
||||
}
|
||||
|
||||
if (!file_util::exists(file)) {
|
||||
throw application_error("Failed to open config file " + file + ": " + strerror(errno));
|
||||
}
|
||||
|
||||
if (!file_util::is_file(file)) {
|
||||
throw application_error("Config file " + file + " is not a file");
|
||||
}
|
||||
|
||||
m_log.trace("config_parser: Parsing %s", file);
|
||||
|
||||
int file_index;
|
||||
|
||||
Reference in New Issue
Block a user