debug icon indicating copy to clipboard operation
debug copied to clipboard

Require gem classes, but out out of require-time side effects?

Open jez opened this issue 3 years ago • 4 comments

Your proposal

Is it possible to separate out the logic to attempt to attach to a process, and to define all the classes that the library needs?

Additional context

When using type checkers like Sorbet, various tools (srb init, tapioca gem, etc.) attempt to require the gem only to see what classes, methods, and constants the gem defines, so that it can generate either an RBS or RBI file providing annotations for the gem.

It seems that the debug gem does not work for those use cases, because requiring the gem seems to try to attach to the gem:

~/sandbox/default  jez@jez-pc-01
❯ cat Gemfile
source 'https://rubygems.org'

gem 'tapioca'
gem 'debug'

~/sandbox/default  jez@jez-pc-01
❯ bundle install &> /dev/null && bundle exec tapioca gem debug
Requiring all gems to prepare for compiling... DEBUGGER: Attaching after process 676571 fork to child process 676585
 Done

Error: Cannot find gem 'debug'

~/sandbox/default  jez@jez-pc-01
❯ export RUBY_DEBUG_ENABLE=0

~/sandbox/default  jez@jez-pc-01
❯ bundle install &> /dev/null && bundle exec tapioca gem debug
Requiring all gems to prepare for compiling...  Done

Error: Cannot find gem 'debug'

What I would like to be able to do is to have a way to require all the supporting classes/modules/constants/methods that the debug gem defines but not have the gem attempt to do any side effects. For example, I want to require the gem but explicitly opt out of the trap and fork interceptors.

The feature request would be considered complete when it's possible to generate an RBS or RBI for the debug gem without having it fail, as shown in the screenshot above.

jez avatar Aug 30 '22 21:08 jez

The failure is likely caused by Tapioca's internal ignoring list. It's added because of https://github.com/Shopify/tapioca/issues/946, which we didn't actually locate the root cause but it's likely related to the TracePoint events of debug after its required.

st0012 avatar Aug 30 '22 21:08 st0012

Whoops sorry about that! For what it’s worth the issue can be reproduced without Tapioca. I can put together a more minimal repro tomorrow.

jez avatar Aug 31 '22 02:08 jez

What should we do for that?

ko1 avatar Sep 16 '22 08:09 ko1

If I'm not mistaken, this issue's goal is the same as #797

st0012 avatar Nov 25 '22 21:11 st0012