Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
## HEAD (unreleased)

- Fix: `SYNTAX_SUGGEST_DEBUG` no longer raises `NoMethodError`. Previously this code path called `$stderr.warn` which is a private method. Now it uses `warn` instead.

## 3.0.0

- Changed: Minimum supported Ruby version is now 3.3. (https://github.com/ruby/syntax_suggest/pull/246)
Expand Down
4 changes: 2 additions & 2 deletions lib/syntax_suggest/core_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def detailed_message(highlight: true, syntax_suggest: true, **kwargs)
end
rescue => e
if ENV["SYNTAX_SUGGEST_DEBUG"]
$stderr.warn(e.message)
$stderr.warn(e.backtrace)
warn(e.message)
warn(e.backtrace)
end

# Ignore internal errors
Expand Down
29 changes: 29 additions & 0 deletions spec/integration/ruby_command_line_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,5 +185,34 @@ class Dog
expect(out).to include("Invalid break")
end
end

it "SYNTAX_SUGGEST_DEBUG reports a rescued internal error instead of masking it" do
Dir.mktmpdir do |dir|
tmpdir = Pathname(dir)

# Force `SyntaxSuggest.call` to raise so the rescue in `detailed_message` fires
monkeypatch = tmpdir.join("raise_monkeypatch.rb")
monkeypatch.write <<~EOM
require "syntax_suggest/api"

module SyntaxSuggest
def self.call(*args, **kwargs)
raise "boom from monkeypatch"
end
end
EOM

script = tmpdir.join("script.rb")
script.write <<~EOM
def lol
puts "haha"
EOM

out = `SYNTAX_SUGGEST_DEBUG=1 #{ruby} -I#{lib_dir} -rsyntax_suggest -r#{monkeypatch} #{script} 2>&1`

expect($?.success?).to be_falsey
expect(out).to include("boom from monkeypatch")
end
end
end
end
Loading