-
Notifications
You must be signed in to change notification settings - Fork 11
Bug: JRuby stacktraces with Java content can fail the reporting #47
base: master
Are you sure you want to change the base?
Bug: JRuby stacktraces with Java content can fail the reporting #47
Conversation
In my case, it was just a regular old LoadError which triggered this sad issue. |
Thanks! A PR would be greatly appreciated 👍 |
@mikker I have questions on desired behavior. I don't quite know how things behave with returned lists of Frame objects. If I add something like this" diff --git a/lib/opbeat/error_message/stacktrace.rb b/lib/opbeat/error_message/stacktrace.rb
index 6133f6f..0bb8704 100644
--- a/lib/opbeat/error_message/stacktrace.rb
+++ b/lib/opbeat/error_message/stacktrace.rb
@@ -27,9 +27,19 @@ module Opbeat
BACKTRACE_REGEX = /^(.+?):(\d+)(?::in `(.+?)')?$/.freeze
+ # regexp (optional leading X: on windows, or JRuby9000 class-prefix)
+ RUBY_INPUT_FORMAT = /
+ ^ \s* (?: [a-zA-Z]: | uri:classloader: )? ([^:]+ | <.*>):
+ (\d+)
+ (?: :in \s `([^']+)')?$
+ /x
+
+ # org.jruby.runtime.callsite.CachingCallSite.call(CachingCallSite.java:170)
+ JAVA_INPUT_FORMAT = /^(.+)\.([^\.]+)\(([^\:]+)\:(\d+)\)$/
+
class << self
def from_line config, line
- _, abs_path, lineno, function = line.match(BACKTRACE_REGEX).to_a
+ abs_path, lineno, function, _module_name = parse_line(line)
lineno = lineno.to_i
filename = strip_load_path(abs_path)
@@ -44,7 +54,21 @@ module Opbeat
private
+ def parse_line(unparsed_line)
+ ruby_match = unparsed_line.match(RUBY_INPUT_FORMAT)
+ if ruby_match
+ _, file, number, method = ruby_match.to_a
+ file.sub!(/\.class$/, '.rb')
+ module_name = nil
+ else
+ java_match = unparsed_line.match(JAVA_INPUT_FORMAT)
+ _, module_name, method, file, number = java_match.to_a
+ end
+ [file, number, method, module_name]
+ end
+
def strip_load_path path
+ return '' unless path
prefix = $:
.map(&:to_s)
.select { |s| path.start_with?(s) } Then the errors get quenched at least, but the new |
@mikker The older Rubies run first. Isn't that a little irritating? Or is it best? |
@mikker I need to push a JRuby test into the Travis matrix. I'll try to get just a single one in there. (And, I added it last, too. Ugh.) |
Apparently Sidekiq 5 can't do Ruby < 2.2. |
@mikker: (Hi! Yes, this got me going on this path. 2.1 is EOL'd. Can we stop supporting < 2.2?) |
We probably could. Can we get away with just freezing Sidekiq to be <5 in ruby 2.2 Gemfiles? |
@mikker Sure can start there. |
gemfiles/Gemfile.base
Outdated
gem 'sidekiq', require: false | ||
# Freeze Sidekiq to < 5 in Ruby 2.2 Gemfiles | ||
if RUBY_VERSION >= '2' | ||
gem 'sidekiq', (RUBY_VERSION >= '2.2.2' ? '~> 5' : '~> 4'), require: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A beautiful line of code 😆 👍🏼
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reminds us of the game "inte nudda golvet", "gulv brænder" etc.
Avoiiiiid the warnings.
@mikker In any event, whether or not this JRuby stacktrace feature can be implemented, the build improvements in this PR could be extracted to their own PR. |
JRuby stacktraces can contain lines that do not conform to the
BACKTRACE_REGEX
pattern, which then returnsnil
instead of matches. Selection on these bad matches will fail with aNoMethodError
for#start_with?
on nil.Gemfile.base
and tests that rely on itstrip_load_path
gets anil
it returns""
(Controversial? I don't know enough to know.)(Update): This is an Issue which was upgraded to a PR after the fact.
Update 2: This is not finished.
Current behavior
See error_message/stacktrace.rb for the code that fails.
Here's the current behavior: Opbeat throws a stacktrace and a "NoMethodError on nil".
Background
Update: The script below as a runnable file: https://gist.github.com/olleolleolle/2a9ba37a0fe774bd484929c0e0f155bb
Here is a way to make a Java exception in JRuby:
Having cut and pasted the
strip_load_path
andBACKTRACE_REGEX
into my irb, I could reproduce the issue with a standard Java error:Example of the stacktrace generated above:
Solution inspiration