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
11 changes: 9 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
### 0.1.11 2026-01-07

- [#19](https://github.com/square/debug_socket/pull/19)
`dup` the `input` before `eval`-ing it so any modifications of `input` do not impact logging.
(@nerdrew)

### 0.1.10 2025-09-05

- #18
Use log level `warn` instead of `unknown` for logging the socket path. (@mdayaram)
- [#18](https://github.com/square/debug_socket/pull/18)
Use log level `warn` instead of `unknown` for logging the socket path.
(@mdayaram)

### 0.1.9 2025-04-03

Expand Down
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ source "https://rubygems.org"
gemspec

gem "base64"
gem "irb"
gem "ostruct"
gem "pry-byebug"
gem "rake"
gem "reline"
gem "rspec", "~> 3.8"
gem "rubocop", "1.73.1"
gem "rubocop-rake"
Expand Down
14 changes: 9 additions & 5 deletions lib/debug_socket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ module Commands
# to run.
def self.isolated_eval(input)
eval(input) # rubocop:disable Security/Eval
# We rescue Exception here because the input could have SyntaxErrors etc.
rescue Exception => e # rubocop:disable Lint/RescueException
DebugSocket.logger&.error { "debug-socket-error=#{e.inspect} input=#{input.inspect} path=#{@path} backtrace=#{e.backtrace.inspect}" }
"#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
end

# Print the backtrace for every Thread
Expand Down Expand Up @@ -63,7 +59,15 @@ def self.start(path, &block)
logger&.warn("debug-socket-command=#{input.inspect}")

perform_audit(input, &block) if block
socket.puts(Commands.isolated_eval(input))
output =
begin
Commands.isolated_eval(input.dup)
# We rescue Exception here because the input could have SyntaxErrors etc.
rescue Exception => e # rubocop:disable Lint/RescueException
logger&.error { "debug-socket-error=#{e.inspect} input=#{input.inspect} path=#{@path} backtrace=#{e.backtrace.inspect}" }
"#{e.class.name}: #{e.message}\n#{e.backtrace.join("\n")}"
end
socket.puts(output)

errors = 0
rescue StandardError => e
Expand Down
2 changes: 1 addition & 1 deletion lib/debug_socket/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DebugSocket
VERSION = "0.1.10"
VERSION = "0.1.11"
end
9 changes: 9 additions & 0 deletions spec/debug_socket_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ def write(str, socket_path = path)
expect(write("server = 1")).to eq("1\n")
end

it "does not allow modifying the input" do
cmd = <<~RUBY
input.define_singleton_method(:inspect) { raise "boom" }
raise "foo"
RUBY
expect(write(cmd)).to include("RuntimeError: foo")
expect(log_buffer.string).to include(cmd.inspect)
end

it "retries socket errors 10 times then dies" do
20.times { sleep(0.1) unless File.exist?(path) }

Expand Down
Loading