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