Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid passing nil path to File.basename #602

Merged
merged 1 commit into from
Mar 30, 2022
Merged

Conversation

st0012
Copy link
Member

@st0012 st0012 commented Mar 30, 2022

Some frames may not aways have path value.

irb((run)@bin/rails:in `require' (not under control)):003:0> frame.location
=> "bin/rails:in `require'"
irb((run)@bin/rails:in `require' (not under control)):004:0> frame.path
=> nil

And when that happens, File.basename(nil) would cause exception and crash the debugger.

DEBUGGER: Connected.
["DEBUGGER Exception: /Users/st0012/projects/debug/lib/debug/thread_client.rb:1038",
 #<TypeError: no implicit conversion of nil into String>,
 ["/Users/st0012/projects/debug/lib/debug/server_dap.rb:623:in `basename'",
  "/Users/st0012/projects/debug/lib/debug/server_dap.rb:623:in `block in process_dap'",
  "/Users/st0012/projects/debug/lib/debug/server_dap.rb:611:in `map'",
  "/Users/st0012/projects/debug/lib/debug/server_dap.rb:611:in `process_dap'",
  "/Users/st0012/projects/debug/lib/debug/thread_client.rb:1027:in `wait_next_action_'",
  "/Users/st0012/projects/debug/lib/debug/thread_client.rb:727:in `wait_next_action'",
  "/Users/st0012/projects/debug/lib/debug/thread_client.rb:284:in `suspend'",
  "/Users/st0012/projects/debug/lib/debug/thread_client.rb:218:in `on_breakpoint'",
  "/Users/st0012/projects/debug/lib/debug/breakpoint.rb:69:in `suspend'",
  "/Users/st0012/projects/debug/lib/debug/breakpoint.rb:161:in `block in setup'",
  "/Users/st0012/projects/debug/lib/debug/session.rb:2002:in `setup_initial_suspend'",
  "/Users/st0012/projects/debug/lib/debug/session.rb:1992:in `open_unix'",
  "/Users/st0012/projects/debug/lib/debug/session.rb:1965:in `open'",
  "/Users/st0012/projects/debug/lib/debug/open.rb:13:in `<top (required)>'",
  "bin/rails:in `require'"]]
/Users/st0012/projects/debug/lib/debug/server_dap.rb:623:in `basename': no implicit conversion of nil into String (TypeError)
        from /Users/st0012/projects/debug/lib/debug/server_dap.rb:623:in `block in process_dap'
        from /Users/st0012/projects/debug/lib/debug/server_dap.rb:611:in `map'
        from /Users/st0012/projects/debug/lib/debug/server_dap.rb:611:in `process_dap'
        from /Users/st0012/projects/debug/lib/debug/thread_client.rb:1027:in `wait_next_action_'
        from /Users/st0012/projects/debug/lib/debug/thread_client.rb:727:in `wait_next_action'
        from /Users/st0012/projects/debug/lib/debug/thread_client.rb:284:in `suspend'
        from /Users/st0012/projects/debug/lib/debug/thread_client.rb:218:in `on_breakpoint'
        from /Users/st0012/projects/debug/lib/debug/breakpoint.rb:69:in `suspend'
        from /Users/st0012/projects/debug/lib/debug/breakpoint.rb:161:in `block in setup'
        from /Users/st0012/projects/debug/lib/debug/session.rb:2002:in `setup_initial_suspend'
        from /Users/st0012/projects/debug/lib/debug/session.rb:1992:in `open_unix'
        from /Users/st0012/projects/debug/lib/debug/session.rb:1965:in `open'
        from /Users/st0012/projects/debug/lib/debug/open.rb:13:in `<top (required)>'
        from bin/rails:in `require'
DEBUGGER: Disconnected.

I can reproduce this with: rdbg --command --open --stop-at-load -- bundle exec rails s on any Rails apps.

(I accidentally added the unnecessary --stop-at-load and found the issue)

截圖 2022-03-30 15 11 35

But of course, there may be a better solution than this patch.

@st0012
Copy link
Member Author

st0012 commented Mar 30, 2022

Actually, I think frame.location.to_s is better. Will update.

Some frames may not aways have `path` value.

```
irb((run)@bin/rails:in `require' (not under control)):003:0> frame.location
=> "bin/rails:in `require'"
irb((run)@bin/rails:in `require' (not under control)):004:0> frame.path
=> nil
```

And when that happens, `File.basename(nil)` would cause exception and crash the debugger.
@ko1 ko1 merged commit dbf8c24 into ruby:master Mar 30, 2022
@st0012 st0012 deleted the fix-dap-error branch April 24, 2022 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants