279 static const std::pair<
const char *,
bool (QNapi::Value::*)()
const> errorPropsDefs[] = {
280 {
"name", &QNapi::Value::IsString},
281 {
"message", &QNapi::Value::IsString},
282 {
"code", &QNapi::Value::IsNumber},
285 Napi::HandleScope funcScope(cbInfo.Env());
287 auto optCbArg = cbInfo.Length() != 0
288 ? cbInfo.getFirstArg<QNapi::Value>(Q_FUNC_INFO)
289 : cbInfo.Env().Undefined();
290 auto error = optCbArg.IsObject()
291 ? QNapi::checkedCast<QNapi::Object>(optCbArg)
292 : QNapi::Object::New(cbInfo.Env());
294 std::string errorDetailsStr;
295 for (
const auto &propDef : errorPropsDefs) {
296 const auto *propName = propDef.first;
297 const auto &typeCheckMemFun = propDef.second;
299 auto optProp = QNapi::getPropOrUndefined(error, propName);
300 if ((optProp.*typeCheckMemFun)()) {
301 std::string propStr = optProp.ToString();
302 if (!errorDetailsStr.empty())
303 errorDetailsStr +=
", ";
304 errorDetailsStr += propName;
305 errorDetailsStr +=
"='";
306 errorDetailsStr += propStr;
307 errorDetailsStr +=
"'";
311 std::string errorStr = errorMessagePrefix;
312 if (!errorDetailsStr.empty()) {
314 errorStr += errorDetailsStr;
317 qOhosPrintfError(
"%s", errorStr.c_str());