Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@arika
Last active July 11, 2017 10:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arika/73d04e89b45e80bd748efd89e09ee6e0 to your computer and use it in GitHub Desktop.
Save arika/73d04e89b45e80bd748efd89e09ee6e0 to your computer and use it in GitHub Desktop.
debug tracing patch for gem error "`check_version_conflict': can't activate foo-2.0, already activated foo-1.0 (Gem::LoadError)"
def ___trace_push mark
Thread.current[:__prefix] ||= ''
Thread.current[:__prefix] << "#{mark} "
end
def ___trace_pop
Thread.current[:__prefix].slice!(-3, 3)
end
def ___trace_puts mark, *msgs
$stderr.print Thread.current[:__prefix]
$stderr.print "#{mark} #{msgs.map {|m| m.is_a?(Array) ? '[' + m.join(', ') + ']' : m.to_s }.join(' ')}\n"
end
module ObjectTrace_
def require path
___trace_puts 'R', path
___trace_push '|'
super.tap do |result|
___trace_pop
___trace_puts (result ? '+' : '`'), path
end
rescue Exception
___trace_pop
___trace_puts 'X', path, 'failed'
raise
end
def gem gem_name, *requirements
Thread.current[:require] ||= []
___trace_puts 'G', gem_name, requirements
super
end
end
Object.prepend(ObjectTrace_)
module GemSpecTrace_
module ClassMethods
def find_active_stub_by_path path
super.tap {|spec| ___trace_puts 'S', spec.full_name if spec }
end
def find_in_unresolved path
super.tap {|specs| ___trace_puts 'U', specs.map(&:full_name) unless specs.empty? }
end
def find_in_unresolved_tree path
___trace_puts 'T', unresolved_deps.values.map { |dep| dep.to_specs }.flatten.map(&:full_name)
___trace_push ':'
super.tap do |specs|
___trace_pop
___trace_puts '`', specs.map(&:full_name)
end
rescue Exception
___trace_pop
___trace_puts 'X', "failed (#{$!})"
raise
end
end
def traverse trail = [], visited = {}, &block
___trace_puts 't', full_name, dependencies.select(&:runtime?).each_with_object({}) {|d,h| h[d.to_s] = d.to_specs.map(&:full_name) }
___trace_push ':'
super
ensure
___trace_pop
end
def activate
___trace_puts 'A', full_name
___trace_push ':'
super.tap do
___trace_pop
___trace_puts '+', full_name
end
rescue Exception
___trace_pop
___trace_puts 'X', full_name, "failed (#{$!})"
raise
end
end
class Gem::Specification
prepend(GemSpecTrace_)
class << self
prepend(GemSpecTrace_::ClassMethods)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment