Navigation Menu

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

Enabling # frozen_string_literal: true in ~/.pryc crashes most operations #1824

Closed
stdedos opened this issue Oct 24, 2018 · 5 comments · Fixed by #2034
Closed

Enabling # frozen_string_literal: true in ~/.pryc crashes most operations #1824

stdedos opened this issue Oct 24, 2018 · 5 comments · Fixed by #2034
Labels

Comments

@stdedos
Copy link

stdedos commented Oct 24, 2018

e.g.

[1] pry(main)> require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
(pry) output error: #<RuntimeError: can't modify frozen String>
[2] pry(main)> require 'nokogiri'; fp = '/home/sntentos/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
# File contents

vs

[1] pry(main)> require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))

Exception: Errno::ENOENT: No such file or directory @ rb_sysopen - ~/1540326167346.xml
--
From: (pry) @ line 1 @ level: 0 of backtrace (of 24).

 => 1: require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
[2] pry(main)> require 'nokogiri'; fp = '/home/sntentos/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
# File contents
@kyrylo
Copy link
Member

kyrylo commented Oct 24, 2018

Sorry, I cannot reproduce this.

% cat ~/.pryrc
# frozen_string_literal: true

Pry.color = true
Pry.editor = 'emacs'

# Rest is omitted
% pry
[1] pry(main)> require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
Errno::ENOENT: No such file or directory @ rb_sysopen - ~/1540326167346.xml
from (pry):1:in `read'

Any details about your pry & ruby versions, or plugins that you use? What else do you have in your pryrc? Does it fail when it contains only that magic comment and nothing else?

@kyrylo kyrylo closed this as completed Nov 3, 2018
@stdedos
Copy link
Author

stdedos commented Nov 3, 2018

I managed to replicate it with a minimum example of:

Working:

# # frozen_string_literal: true

Pry.config.exception_handler = proc do |_output, _exception, _pry_|
  _pry_.run_command 'cat --ex'
end

Failing:

# frozen_string_literal: true

Pry.config.exception_handler = proc do |_output, _exception, _pry_|
  _pry_.run_command 'cat --ex'
end

Having only the magic comment yields:

[1] pry(main)> require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp))
Errno::ENOENT: No such file or directory @ rb_sysopen - ~/Documents/Forcepoint/WIP/1540326167346_subtest_setup.28_original_test_bba_configure_ATF_Cluster_output.xml
from (pry):1:in `read'

but I prefer the more extensive version (not for the example or the REPL per se, but for debugging reasons i.e. using it with pry-byebug)


Ruby / Pry version

$ ruby --version
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]
$ pry --version
Pry version 0.10.3 on Ruby 2.3.1

Side question: Can I somehow write the Pry.config.exception_handler differently? Rubocop complains for the _pry_ with UnderscorePrefixedVariableName (since the file is marked as Ruby Source Code, it goes through Rubocop).

However, an example of creating new pry commands is:

# Hit Enter to repeat last command
Pry::Commands.command(/^$/, 'repeat last command') do
  _pry_.run_command Pry.history.to_a.last
end

So, I am not sure if _pry_ is something special, or something else

@kyrylo
Copy link
Member

kyrylo commented Nov 3, 2018

Can you try upgrading Pry? The latest version is 0.11.3.

@stdedos
Copy link
Author

stdedos commented Nov 3, 2018

[1] pry(main)> require 'nokogiri'; fp = '~/1540326167346.xml' ; doc = Nokogiri::XML.parse(File.read(fp));
(pry) output error: #<RuntimeError: can't modify frozen String>
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/command.rb:335:in `replace'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/command.rb:335:in `tokenize'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/command.rb:365:in `process_line'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/command_set.rb:400:in `process_line'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:450:in `run_command'
/home/sntentos/.pryrc:4:in `block in __pry__'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:365:in `show_result'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:336:in `block in handle_line'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_class.rb:395:in `critical_section'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:335:in `handle_line'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:243:in `block (2 levels) in eval'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:242:in `catch'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:242:in `block in eval'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:241:in `catch'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_instance.rb:241:in `eval'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:77:in `block in repl'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:67:in `loop'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:67:in `repl'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:38:in `block in start'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/input_lock.rb:61:in `__with_ownership'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/input_lock.rb:79:in `with_ownership'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:38:in `start'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/repl.rb:13:in `start'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/pry_class.rb:192:in `start'
/var/lib/gems/2.3.0/gems/pry-byebug-3.6.0/lib/pry-byebug/pry_ext.rb:11:in `start_with_pry_byebug'
/var/lib/gems/2.3.0/gems/pry-0.11.3/lib/pry/cli.rb:116:in `start'
/var/lib/gems/2.3.0/gems/pry-0.11.3/bin/pry:12:in `<top (required)>'
/usr/local/bin/pry:23:in `load'
/usr/local/bin/pry:23:in `<main>'
$ pry --version
Pry version 0.11.3 on Ruby 2.3.1

@kyrylo kyrylo reopened this Nov 3, 2018
@kyrylo
Copy link
Member

kyrylo commented May 2, 2019

Rubocop complains for the pry with UnderscorePrefixedVariableName (since the file is marked as Ruby Source Code, it goes through Rubocop).

Small update here _pry_ was renamed to pry_instance on master.

The rest is in the same state. I also managed to reproduce this. I guess the proper fix would be using frozen Strings ourselves.

@kyrylo kyrylo added this to the v0.13.0 milestone May 2, 2019
@kyrylo kyrylo added the bug label May 2, 2019
kyrylo added a commit that referenced this issue May 3, 2019
This change is a preparational step for #1824 (Enabling `frozen_string_literal:
true` in `~/.pryc` crashes most operations).

The handler was mutating `eval_string` that we pass, and this behaviour will
stop working in Ruby 3.

I was pondering about keeping this option but couldn't come up with an easy
solution. I made a GitHub search to see if anybody uses it, and it seems like
nobody configures it. I am not sure why anybody would want to do that, so I hope
it won't be missed.

The handler's behaviour wasn't deleted, it is still in place. We just moved the
handler's code to `pry_instance.rb`.
kyrylo added a commit that referenced this issue May 3, 2019
This change is a preparational step for #1824 (Enabling `frozen_string_literal:
true` in `~/.pryc` crashes most operations).

The handler was mutating `eval_string` that we pass, and this behaviour will
stop working in Ruby 3.

I was pondering about keeping this option but couldn't come up with an easy
solution. I made a GitHub search to see if anybody uses it, and it seems like
nobody configures it. I am not sure why anybody would want to do that, so I hope
it won't be missed.

The handler's behaviour wasn't deleted, it is still in place. We just moved the
handler's code to `pry_instance.rb`.
kyrylo added a commit that referenced this issue May 4, 2019
This is a preparational step for #1824
(Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations)

Alternative to #2030
(config: delete the `control_d_handler` option)

We had to jump a few hoops to change how the handler works. The problem is that
mutation is the default expected behaviour. Therefore, we had to change its
API. There's no need to pass `eval_string` because `pry_instance` already has it
as an attribute.

`config.control_d_handler` is a proxy proc, to preserve backwards compatibility
with users of old signature (one known user is Pry Byebug). The handler will
emit a warning if the old signature is used.
kyrylo added a commit that referenced this issue May 4, 2019
This is a preparational step for #1824
(Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations)

Alternative to #2030
(config: delete the `control_d_handler` option)

We had to jump a few hoops to change how the handler works. The problem is that
mutation is the default expected behaviour. Therefore, we had to change its
API. There's no need to pass `eval_string` because `pry_instance` already has it
as an attribute.

`config.control_d_handler` is a proxy proc, to preserve backwards compatibility
with users of old signature (one known user is Pry Byebug). The handler will
emit a warning if the old signature is used.
kyrylo added a commit that referenced this issue May 4, 2019
This is a preparational step for #1824
(Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations)

Alternative to #2030
(config: delete the `control_d_handler` option)

We had to jump a few hoops to change how the handler works. The problem is that
mutation is the default expected behaviour. Therefore, we had to change its
API. There's no need to pass `eval_string` because `pry_instance` already has it
as an attribute.

`config.control_d_handler` is a proxy proc, to preserve backwards compatibility
with users of old signature (one known user is Pry Byebug). The handler will
emit a warning if the old signature is used.
kyrylo added a commit that referenced this issue May 4, 2019
This is a preparational step for #1824
(Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most operations)

Alternative to #2030
(config: delete the `control_d_handler` option)

We had to jump a few hoops to change how the handler works. The problem is that
mutation is the default expected behaviour. Therefore, we had to change its
API. There's no need to pass `eval_string` because `pry_instance` already has it
as an attribute.

`config.control_d_handler` is a proxy proc, to preserve backwards compatibility
with users of old signature (one known user is Pry Byebug). The handler will
emit a warning if the old signature is used.
kyrylo added a commit that referenced this issue May 7, 2019
Fixes #1824 (Enabling `# frozen_string_literal: true` in `~/.pryc` crashes most
operations)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants