[Crash Reporting] Getting JS Stacktrace in Native

[Crash Reporting] Getting JS Stacktrace in Native
0.0 0

#1

Hello,

How do i get trace for javascript error which occur in native builds ( ios, android). JS error are shown in logs as
JS Error: error message

but crashlytics does not understand this as error. To log this type of error we tried to manually log error in
Scriptingcore.cpp’s js_log function as

if(strstr(_js_log_buf,"Error")){
  crashlytics_context->log(crashlytics_context,_js_log_buf);
  cocos2d::JniMethodInfo t;
  if(cocos2d::JniHelper::getStaticMethodInfo(t, "org/cocos2dx/javascript/Analytics", "flushCrashLogs", "()V"))
  {
     t.env->CallStaticVoidMethod(t.classID, t.methodID);
     t.env->DeleteLocalRef(t.classID);
  }
}

and in flushCrashlogs we throw a non-fatal exception so the log is pushed to crashlytics.
but using this method we are not able to get stacktrace.
So can someone help us finding a better approach for tracking js error in native such that we can get stacktrace and local variable?

Thank you :smile:


#2

Have you tried the javascript onerror function?


#3

can you post some reference for the onerror function?


#5

@schngrg if you are talking about window.onerror method it is not working in Native mode.

Thank you.


#6

This is an important feature to me as well, since most of the errors would come from JavaScript, instead of native code. Since they are not fatal and only logged to the console, currently there is no way to catch them and report them.

The SDKBOX plugins for Flurry and Apteligent are good for native error handling, but since the JS errors don’t throw such errors they are useless.

If cocos2d-js would send non-fatal exceptions with the stack trace and variables so that the application continues to run, but error reporting frameworks can catch them and report them back to us, this would help immensely with debugging and development.


#7

Any news on this? It would be really helpful!