Repository navigation
Loading debug gem breaks blankslate gem #757
Description
Activity
- changed the title
[-]Loading `debug` gem breaks `BlankSlate`[/-][+]Loading `debug` gem breaks `blankslate` gem[/+]on Sep 21, 2022 This problem breaks one of Stripe's services in development because we start a debug session when it starts up, before it requires the blankslate gem. We are working around the issue, but it would be great if it could be fixed!
Thank you for the report.
I didn't know theblankslatebut could you make a smaller repro-code without theblankslategem?
Otherwise I'll try to make it.minitest also breaks, see minitest/minitest#929
Here is blankslate torn all the way down to a minimal repro:
#!/usr/bin/env ruby -vw class BlankSlate def self.hide(name) return unless instance_methods.include? name undef_method name end hide :singleton_method_added end begin BlankSlate.new.singleton_method_added rescue NoMethodError => e p e.message.include?("private method") ? :GOOD : :BAD else p :BAD end __END__ % ruby -rdebug debug_blankslate.rb :BAD % ruby debug_blankslate.rb :GOOD
run w/o
ruby -rdebugto output GOOD and run withruby -rdebugto output BAD...It essentially boils down to "is singleton_method_added defined?"
for minitest/mock, not too dissimilar:
#!/usr/bin/env ruby -vw class Mock overridden_methods = %w[ === class inspect instance_eval instance_variables object_id public_send respond_to_missing? send to_s ] instance_methods.each do |m| undef_method m unless overridden_methods.include?(m.to_s) || m =~ /^__/ end def method_missing sym, *args, **kwargs, &block # :nodoc: raise NoMethodError, "unmocked method %p" % [sym] end end foo = Mock.new def foo.bar = 'very awesome foo' p :GOOD
I think in my case I'm going to add
singleton_method_addedtooverridden_methodsifDEBUGGER__is defined.
Your environment
ruby -v: ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-linux]rdbg -v: rdbg 1.6.2Describe the bug
The
debuggem undefines and redefinessingleton_method_added.The
blankslategem provides a "abstract base class with no predefined methods" except for some core Ruby builtins. "BlankSlate is useful as a base class when writing classes that depend uponmethod_missing(e.g. dynamic proxies)", so it only works ifsingleton_method_addedis available. However, it hidessingleton_method_addedbecause it's redefined by thedebuggem.This problem does not occur when the
debuggem is not required.To Reproduce
Buggy output -- the method isn't defined:
Expected behavior
The method is defined, but private:
Workaround
We can work around the bug by explicilty unhiding this method, or by requiring
blankslatebeforedebug:Additional context
The problem is caused by this code in the debug gem:
debug/lib/debug/session.rb
Lines 1686 to 1689 in 19b4dde
Why does the debug gem redefine this method?