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

JRuby: unable to capture Java exceptions #2043

Closed
richard-kramer opened this issue May 17, 2023 · 3 comments
Closed

JRuby: unable to capture Java exceptions #2043

richard-kramer opened this issue May 17, 2023 · 3 comments
Assignees
Milestone

Comments

@richard-kramer
Copy link
Contributor

Issue Description

Using sentry in JRuby, it is not possible to directly capture exceptions, which originated in java, as they do not inherit from Exception.

Currently, the only ways to log these exceptions, would be to wrap the Java exception in a custom Ruby exception an pass that to Sentry or to patch the is_a? method on the Java exception to respond with true if Exception is passed. Both solutions don't really seem that clean.

I also submitted an issue over at JRuby, but it seems that behavior is intended. Java exceptions inherit from Java::JavaLang::Error and Java::JavaLang::Throwable, so maybe one of those (probably Java::JavaLang::Throwable) could be added to the type check in JRuby?

Reproduction Steps

The following snippet enters the rescue block, but the exception cannot be captured:

begin
  raise java.lang.OutOfMemoryError.new("A Java error")
rescue Exception => e
  e.is_a?(Exception) # => false
  Sentry.capture_exception(e) # => expect the argument to be a Exception, got Java::JavaLang::OutOfMemoryError (java.lang.OutOfMemoryError: A Java error)
end

Expected Behavior

The exception can be captured by Sentry as it should respond to the expected interface of an exception.

Actual Behavior

Capturing the exception results in an error thrown by sentry because of this type check.

Ruby Version

jruby-9.2.20.0

SDK Version

5.5.0

Integration and Its Version

sentry-rails (5.5.0)

Sentry Config

No response

@sl0thentr0py
Copy link
Member

thanks @richard-kramer we should definitely support this if possible. PRs are always welcome, otherwise I'll take a look at the possibilities when I have some time.

richard-kramer added a commit to richard-kramer/sentry-ruby that referenced this issue May 17, 2023
richard-kramer added a commit to richard-kramer/sentry-ruby that referenced this issue May 17, 2023
@richard-kramer
Copy link
Contributor Author

I created #2044 as a simple fix. Hopefully, this is already enough.

@st0012
Copy link
Collaborator

st0012 commented Jun 7, 2023

@richard-kramer I think this can be closed?

(Meant to just click comment 🤦‍♂️ )

@st0012 st0012 closed this as completed Jun 7, 2023
@st0012 st0012 added this to the 5.10.0 milestone Jun 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants