Better error message when world size and rank are set as strings (#8316)

Co-authored-by: jiamingy <jm.yuan@outlook.com>
This commit is contained in:
Rong Ou
2022-10-12 00:53:25 -07:00
committed by GitHub
parent 210915c985
commit 39afdac3be
6 changed files with 79 additions and 31 deletions

View File

@@ -248,13 +248,23 @@ inline void GenerateFeatureMap(Learner const *learner,
void XGBBuildInfoDevice(Json* p_info);
template <typename JT>
void TypeCheck(Json const &value, StringView name) {
using T = std::remove_const_t<JT> const;
if (!IsA<T>(value)) {
LOG(FATAL) << "Incorrect type for: `" << name << "`, expecting: `" << T{}.TypeStr()
<< "`, got: `" << value.GetValue().TypeStr() << "`.";
}
}
template <typename JT>
auto const &RequiredArg(Json const &in, std::string const &key, StringView func) {
auto const &obj = get<Object const>(in);
auto it = obj.find(key);
if (it == obj.cend() || IsA<Null>(it->second)) {
LOG(FATAL) << "Argument `" << key << "` is required for `" << func << "`";
LOG(FATAL) << "Argument `" << key << "` is required for `" << func << "`.";
}
TypeCheck<JT>(it->second, StringView{key});
return get<std::remove_const_t<JT> const>(it->second);
}
@@ -262,7 +272,8 @@ template <typename JT, typename T>
auto const &OptionalArg(Json const &in, std::string const &key, T const &dft) {
auto const &obj = get<Object const>(in);
auto it = obj.find(key);
if (it != obj.cend()) {
if (it != obj.cend() && !IsA<Null>(it->second)) {
TypeCheck<JT>(it->second, StringView{key});
return get<std::remove_const_t<JT> const>(it->second);
}
return dft;