Skip to content

Commit d67588c

Browse files
authored
feat: log the fullMessage with more details about the error (#229)
1 parent c3a01ea commit d67588c

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

NativeScript/runtime/NativeScriptException.mm

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,20 @@
3737
bool success = global->Get(context, tns::ToV8String(isolate, cbName)).ToLocal(&handler);
3838

3939
std::string stackTrace = GetErrorStackTrace(isolate, message->GetStackTrace());
40+
std::string fullMessage;
41+
42+
auto errObject = error.As<Object>();
43+
auto fullMessageString = tns::ToV8String(isolate, "fullMessage");
44+
if(errObject->HasOwnProperty(context, fullMessageString).ToChecked()) {
45+
// check if we have a "fullMessage" on the error, and log that instead - since it includes more info about the exception.
46+
auto fullMessage_ = errObject->Get(context, fullMessageString).ToLocalChecked();
47+
fullMessage = tns::ToString(isolate, fullMessage_);
48+
} else {
49+
Local<v8::String> messageV8String = message->Get();
50+
std::string messageString = tns::ToString(isolate, messageV8String);
51+
fullMessage = messageString + "\n at \n" + stackTrace;
52+
}
53+
4054
if (success && handler->IsFunction()) {
4155
if (error->IsObject()) {
4256
tns::Assert(error.As<Object>()->Set(context, tns::ToV8String(isolate, "stackTrace"), tns::ToV8String(isolate, stackTrace)).FromMaybe(false), isolate);
@@ -56,9 +70,7 @@
5670
}
5771

5872
if (!isDiscarded) {
59-
Local<v8::String> messageV8String = message->Get();
60-
std::string messageString = tns::ToString(isolate, messageV8String);
61-
NSString* name = [NSString stringWithFormat:@"NativeScript encountered a fatal error: %s\n at \n%s", messageString.c_str(), stackTrace.c_str()];
73+
NSString* name = [NSString stringWithFormat:@"NativeScript encountered a fatal error:\n\n%s", fullMessage.c_str()];
6274
// we throw the exception on main thread
6375
// otherwise it seems that when getting NSException info from NSSetUncaughtExceptionHandler
6476
// we are missing almost all data. No explanation for why yet

0 commit comments

Comments
 (0)