275 static const std::pair<
const char *,
bool (QNapi::Value::*)()
const> errorPropsDefs[] = {
276 {
"name", &QNapi::Value::IsString},
277 {
"message", &QNapi::Value::IsString},
278 {
"code", &QNapi::Value::IsNumber},
281 Napi::HandleScope funcScope(cbInfo.Env());
283 auto optCbArg = cbInfo.Length() != 0
284 ? cbInfo.getFirstArg<QNapi::Value>(Q_FUNC_INFO)
285 : cbInfo.Env().Undefined();
286 auto error = optCbArg.IsObject()
287 ? QNapi::checkedCast<QNapi::Object>(optCbArg)
288 : QNapi::Object::New(cbInfo.Env());
290 std::string errorDetailsStr;
291 for (
const auto &propDef : errorPropsDefs) {
292 const auto *propName = propDef.first;
293 const auto &typeCheckMemFun = propDef.second;
295 auto optProp = QNapi::getPropOrUndefined(error, propName);
296 if ((optProp.*typeCheckMemFun)()) {
297 std::string propStr = optProp.ToString();
298 if (!errorDetailsStr.empty())
299 errorDetailsStr +=
", ";
300 errorDetailsStr += propName;
301 errorDetailsStr +=
"='";
302 errorDetailsStr += propStr;
303 errorDetailsStr +=
"'";
307 std::string errorStr = errorMessagePrefix;
308 if (!errorDetailsStr.empty()) {
310 errorStr += errorDetailsStr;
313 qOhosPrintfError(
"%s", errorStr.c_str());