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