Skip to content

Commit

Permalink
fix: some crashes at log configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Dmitriy Khaustov aka xDimon <[email protected]>
  • Loading branch information
xDimon committed Oct 14, 2024
1 parent 42348f2 commit 1947561
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/impl/configurator_from_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ namespace soralog {
try {
node = YAML::LoadFile(arg);
} catch (const std::exception &exception) {
errors_ << "E: Can't parse file `"
<< std::filesystem::canonical(arg).string()
<< "': " << exception.what() << "\n";
errors_ << "E: Can't parse file "
<< std::filesystem::weakly_canonical(arg) << ": "
<< exception.what() << "\n";
has_error_ = true;
}

Expand Down
19 changes: 14 additions & 5 deletions src/logging_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
#include <soralog/impl/sink_to_nowhere.hpp>
#include <soralog/logger.hpp>

namespace soralog {
using std::literals::string_literals::operator""s;

namespace soralog {
LoggingSystem::LoggingSystem(std::shared_ptr<Configurator> configurator)
: configurator_(std::move(configurator)) {
makeSink<SinkToNowhere>("*");
Expand Down Expand Up @@ -63,7 +64,16 @@ namespace soralog {
throw std::logic_error("LoggerSystem is already configured");
}
is_configured_ = true;
auto result = configurator_->applyOn(*this);

Configurator::Result result;
try {
result = configurator_->applyOn(*this);
} catch (const std::exception &exception) {
result.message += "E: Configure is failed: "s + exception.what() + "; "
+ "Logging system is unworkable\n";
result.has_error = true;
return result;
}

if (groups_.empty()) {
result.message +=
Expand All @@ -77,9 +87,8 @@ namespace soralog {
continue;
}
if (group->sink()->name() == "*") {
result.message += //
"W: Group '" + name + "' has undefined sink; "
"Sink to nowhere will be used\n";
result.message += "W: Group '" + name + "' has undefined sink; "
+ "Sink to nowhere will be used\n";
result.has_warning = true;
}
}
Expand Down

0 comments on commit 1947561

Please sign in to comment.