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