Created
December 14, 2011 01:21
-
-
Save bryanstearns/1474782 to your computer and use it in GitHub Desktop.
config/initializers/backtrace_links.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# See http://selfamusementpark.com/blog/2011/12/13/rubymine-firefox-and-exception-backtraces/ | |
# | |
# In Rubymine, do File -> Create Command-line Launcher | |
# -- name it "mine", put in /usr/local/bin | |
# | |
# Also, create executable /usr/local/bin/firefox_to_mine with: | |
# #!/usr/bin/ruby | |
# url = ARGV.first | |
# if url =~ /^mine\:([^\?]+)\?(.*)$/ | |
# `mine --line #{$2} #{$1}` | |
# else | |
# abort "Invalid parameter: #{url.inspect}" | |
# end | |
# | |
# In Firefox: register a new protocol handler: | |
# --about:config | |
# --right-click -> New -> Boolean | |
# name: network.protocol-handler.expose.mine | |
# value: false | |
# | |
# Then, when you get an exception and click on one of the links, choose | |
# /usr/local/bin/firefox_to_mine as the handler. | |
# | |
EXCEPTION_PATH_FILTERS = [ | |
[ENV["GEM_HOME"] + "/gems", 'gems'], | |
[ENV["MY_RUBY_HOME"], 'ruby'], | |
[Dir.getwd, File.basename(Dir.getwd)] | |
] | |
class Exception | |
%w[application_backtrace framework_backtrace clean_backtrace].each do |method| | |
define_method("#{method}_with_linking_join") do | |
result = send("#{method}_without_linking_join") | |
class << result | |
def join(sep=$,) | |
lines = self.map do |line| | |
if line =~ /^([^:]+):(\d+):(.*)$/ | |
path, number, details = $1, $2, $3 | |
short_path = path.dup | |
EXCEPTION_PATH_FILTERS.each do |prefix, nickname| | |
short_path.sub!(prefix, nickname) if path.starts_with?(prefix) | |
end | |
line = "<a href=\"mine:#{path}?#{number}\">#{short_path}:#{number}</a>:#{details}" | |
end | |
line | |
end.join(sep) | |
true | |
lines | |
end | |
end | |
result | |
end | |
alias_method_chain method.to_sym, :linking_join | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment