Skip to content

Commit

Permalink
[gbdt] enhance error handling for forced splits file loading
Browse files Browse the repository at this point in the history
  • Loading branch information
KYash03 committed Feb 16, 2025
1 parent d02a01a commit 0cd73e5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/boosting/gbdt.cpp
Original file line number Diff line number Diff line change
@@ -83,10 +83,20 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective
// load forced_splits file
if (!config->forcedsplits_filename.empty()) {
std::ifstream forced_splits_file(config->forcedsplits_filename.c_str());
if (!forced_splits_file.good()) {
Log::Fatal("Could not open forced splits file: %s", config->forcedsplits_filename.c_str());
}
std::stringstream buffer;
buffer << forced_splits_file.rdbuf();
std::string err;
forced_splits_json_ = Json::parse(buffer.str(), &err);
if (!err.empty()) {
Log::Fatal("Failed to parse forced splits file %s. JSON error: %s",
config->forcedsplits_filename.c_str(), err.c_str());
}
if (forced_splits_json_.size() == 0) {
Log::Warning("Empty forced splits file: %s", config->forcedsplits_filename.c_str());
}
}

objective_function_ = objective_function;

0 comments on commit 0cd73e5

Please sign in to comment.