Skip to content

Commit 7e35462

Browse files
committed
[gbdt] enhance error handling for forced splits file loading
1 parent 604e2c5 commit 7e35462

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/boosting/gbdt.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,20 @@ void GBDT::Init(const Config* config, const Dataset* train_data, const Objective
8383
// load forced_splits file
8484
if (!config->forcedsplits_filename.empty()) {
8585
std::ifstream forced_splits_file(config->forcedsplits_filename.c_str());
86+
if (!forced_splits_file.good()) {
87+
Log::Fatal("Could not open forced splits file: %s", config->forcedsplits_filename.c_str());
88+
}
8689
std::stringstream buffer;
8790
buffer << forced_splits_file.rdbuf();
8891
std::string err;
8992
forced_splits_json_ = Json::parse(buffer.str(), &err);
93+
if (!err.empty()) {
94+
Log::Fatal("Failed to parse forced splits file %s. JSON error: %s",
95+
config->forcedsplits_filename.c_str(), err.c_str());
96+
}
97+
if (forced_splits_json_.size() == 0) {
98+
Log::Warning("Empty forced splits file: %s", config->forcedsplits_filename.c_str());
99+
}
90100
}
91101

92102
objective_function_ = objective_function;

0 commit comments

Comments
 (0)