Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C++ NoMethodError Exception does not provide anything useful in sentry.io UI #935

Open
3 of 10 tasks
georges opened this issue Feb 4, 2021 · 16 comments
Open
3 of 10 tasks

Comments

@georges
Copy link

georges commented Feb 4, 2021

Platform:

  • iOS
  • tvOS
  • MacOS
  • watchOS

Swift:

  • Yes -> If yes, which version?
  • No

sentry-cocoa installed with:

  • Swift Package Manager
  • CocoaPods
  • Carthage
  • Manually

Version of sentry-cocoa:
6.0.10


I have following issue:

I've receive sentry report of C++ Exception NoMethodError events. When I look at the various thread dump attached, there is nothing useful, i.e. I can't see an place in the code that would have triggered that exception.

I see a couple threads in

Transceive 0x0001000fb29c handleExceptions (Sentry/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c:258)

and

Transceive 0x0001000fb2d2 handleExceptions (Sentry/Sources/SentryCrash/Recording/Monitors/SentryCrashMonitor_MachException.c:266)

but nothing more specific about my application itself.

Am I missing something? Happy to provide more details, I don't know what would help.

@philipphofmann
Copy link
Member

Hi, @georges,
Can you maybe share a link to the issue in Sentry so we can see more context?

@georges
Copy link
Author

georges commented Feb 4, 2021

@philipphofmann
Copy link
Member

It seems like we are not able to get the thread that causes the error. A NoMethodError is more typical for Ruby, but the error message states it's coming from C++. The breadcrumbs state that this usually happens after a few hours the app went to the background. Can you maybe elaborate on when this error is happening? Can you reproduce it somehow?

@mitsuhiko
Copy link
Member

@georges I took the liberty to investigate this particular issue on your account and the error you see here is indeed raised by an embedded ruby runtime. Could it be that you're invoking an embedded ruby script that raises that error? If that's the case you might have to capture the ruby error at the boundary. Depending on your setup you might be able to capture the errors within your embedded ruby interpreter with the ruby SDK and report them separately and then silence them elsewhere.

I'm assuming whatever it is you're using will propagate ruby exceptions (which are normally 'thrown' via longjmp) into a regular C++ exception at the boundary. If we can capture a stack trace for C++ exceptions or not depends on if __cxa_throw can be hooked (

extern "C" {
void __cxa_throw(void *thrown_exception, std::type_info *tinfo, void (*dest)(void *))
__attribute__((weak));
void
__cxa_throw(void *thrown_exception, std::type_info *tinfo, void (*dest)(void *))
{
if (g_captureNextStackTrace) {
sentrycrashsc_initSelfThread(&g_stackCursor, 1);
}
static cxa_throw_type orig_cxa_throw = NULL;
unlikely_if(orig_cxa_throw == NULL)
{
orig_cxa_throw = (cxa_throw_type)dlsym(RTLD_NEXT, "__cxa_throw");
}
orig_cxa_throw(thrown_exception, tinfo, dest);
__builtin_unreachable();
}
}
) This sometimes does not work when c++ is used in shared libraries and requires the sentry SDK to be compiled into the same binary. This is unfortunately largely a limitation of C++ itself.

@georges
Copy link
Author

georges commented Feb 12, 2021

Thanks for investigating. I should have mentioned that this is a macOS app built with RubyMotion, hence why there are ruby references there. However, as far as I can understand, it's not interpreted but compiled. RubyMotion is an evolution of MacRuby, an implementation of Ruby 1.9 directly on top of Mac OS X core technologies such as the Objective-C runtime and garbage collector, the LLVM compiler infrastructure and the Foundation and ICU frameworks.

I don't understand all the magic that's involved there, only that it makes the programer life an order of magnitude happier :)

So based on your suggestion, I'm gonna try to see if I can explicitly trap NoMethodError exception. What would be the best mechanism to send that information to Sentry so that it shows up as an event?

@philipphofmann
Copy link
Member

@mitsuhiko according to the docs, RubyMotion uses the Objective-C runtime and is completely different than CRuby.

@georges, how do you use Sentry in your project? Does it work for other types of errors?

@mitsuhiko
Copy link
Member

@georges for native errors to have sensible back traces they need to be captured where the exception is raised, not where it's captured. For different languages we do this in different ways. My guess is that RubyMotion does this in a way we do not support currently. I'm not sure how RubyMotion works but potentially you can use the ruby SDK we provide and capture exceptions at the boundary between objc and ruby. Though not sure if the SDK supports RubyMotion.

@georges
Copy link
Author

georges commented Feb 20, 2021

@philipphofmann I use the sentry sdk like a Objective-C app would. It works reasonably well with most crash. For example here it did provide the right stack trace for a similar NoMethodError

https://sentry.io/organizations/island-magic-co/issues/2217648132/events/fa3c992f29524ce1a358da152c6860ff/

I understand I'm probably using the sdk not in the way it was intended. Just wanted to make sure I'm not missing something simple in the configuration.

BTW, I tried to use
NSSetUncaughtExceptionHandler
to hook exception but it does not seem to work for me on macOS.

@philipphofmann
Copy link
Member

philipphofmann commented Jan 5, 2022

Maybe merging some of the latest changes from KSCrashMonitor_MachException to SentryCrashMonitor_MachException could solve the issue.

The same applies for KSCrashMonitor_CPPException

@georges
Copy link
Author

georges commented Sep 12, 2022

Could be useful to look at the fixes added in:
https://github.com/bugsnag/bugsnag-cocoa/blob/master/Bugsnag/KSCrash/Source/KSCrash/Recording/Sentry/BSG_KSCrashSentry_CPPException.mm

That seems to solve crashes related with C++ Exceptions

@brustolin
Copy link
Contributor

Thanks @georges. We'll take a look.

@philipphofmann
Copy link
Member

We did some fixes with #1735 released in 7.12.0 and #2662 released in 8.1.0 that could solve this problem. Do you still see it happening, @georges?

@georges
Copy link
Author

georges commented Feb 1, 2023

Still a problem with 7.31.5. I can't test with 8.1.0 because of the swift dependency.

@philipphofmann
Copy link
Member

Thanks for the update, @georges. Can you share some insights on why you can't update because of the Swift dependency?

@georges
Copy link
Author

georges commented Feb 2, 2023

RubyMotion does not support Swift based cocoapods. There might be some workaround but I did not investigate further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Backlog
Development

No branches or pull requests

6 participants