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
whereami gets confused in a Dir.chdir block #1220
Comments
What makes you think it is an OS filesystem permissions problem? To me the problem seems pretty straightforward: whereami looks in the current directory and expects to find my script (foo.rb) but Dir.chdir has changed the directory on us so it doesn't find it. I had a problem trying to install pry-rescue so I couldn't try that right away. However, there isn't necessarily an exception or permission error, I just want to go to a certain line of code and look around. Since I use Dir.chdir blocks extensively this almost seems like a deal-breaker. Really hope it can be fixed because I'd like to continue to reap the benefits of pry. Thanks. |
It can't open the file because it doesn't exist. I can work around the problem by copying the script to the temp directory, like this:
But that's not really a satisfactory workaround for me. THanks. |
Hi Johnny, I'm not trying to be difficult here, but try and imagine why this is not a satisfactory workaround for me. Since most of my code is in Dir.chdir blocks, this issue means that EVERY TIME I want to use pry and whereami (and next and step from pry-nav) I have to remember what my current directory is, and the directory where the script is, and copy the file. Then when I'm done I have to remove the file because its presence will cause unintended side effects (my code only expects certain files to be in certain directories). I wish I was familiar enough with the pry code to offer you a pull request, but it does seem that the problem is pretty easy to fix. When pry starts, you store the directory of the script it's running, accessible with If I have some time I might try and fix it but I might cause more problems than I solve. ;) |
Looked into this a bit. Short of watching the Dir#chdir method and storing a variable that contains the old path I'm not sure how this could be handled. It looks like when a block is given to Dir#chdir in C-land it stores old path in a struct: https://github.com/ruby/ruby/blob/trunk/dir.c#L781 Then ensures that the current working directory gets set back to this. https://github.com/ruby/ruby/blob/trunk/dir.c#L878 Unfortunately, I couldn't find a way to grab that value. Thought of using a method watcher like mwoods79/bubot to store a var to old path and reference it in whereami#setup. But that seems pretty heavy handed, and there might be side effects that I haven't thought of. Anyways, my two cents. :)))) |
I don't see why you need to watch Dir#chdir. How about just always examining source code files relative to |
@dtenenba If you execute And if you try to expand the path it ends up using the current working directory, which in this case is inside a tmp directory. And the file doesn't exist there. |
@rondale-sc, I see the problem. That's too bad. I found another workaround that is slightly less annoying, and that is to add another binding.pry before my Dir.chdir block. Then when I hit that first one, I just press control-D and then I'm in the Dir.chdir block but whereami works just fine. It's still technically an issue but I don't know if it can be fixed. So I'll leave it up to someone else to close this or not. Seems that Dir.chdir should maintain a stack somewhere that can be accessed programmatically. At least I wish it did. |
@dtenenba Would be great if you could access the old path. I did think about keeping a stack internal to Pry that'd store the dir value and push the new path each time the directory changed. But that seems pretty unwieldy. Anyways, good luck. Sorry I couldn't help out here. :) |
This is definitely an issue that keeps plaguing us when debugging our builders. |
I'm still getting this issue three years after it was first reported. Any movement on this? |
The culprit looks like this call to If you remove the I'm not sure why we need to expand the path -- Thoughts? |
@epitron Ruby 1.9 now there is |
Oh, so Ruby 1.9 gives relative paths in |
What about |
Hello, I have the following script foo.rb:
If I run it like this:
Then when I get dropped into pry I type 'whereami' and see:
Is there any way around that? Can whereami work off the directory it was in when the script was invoked, not the one it's in when
binding.pry
is invoked?I also use pry as a debugger with pry-nav, and experience the same problem when I step into a Dir.chdir block.
The text was updated successfully, but these errors were encountered: