Skip to content

fix(server): allow STDOUT#puts with no arguments (blank line)#24

Open
crossi-dev wants to merge 1 commit into
terminalwire:mainfrom
crossi-dev:fix/6-empty-puts
Open

fix(server): allow STDOUT#puts with no arguments (blank line)#24
crossi-dev wants to merge 1 commit into
terminalwire:mainfrom
crossi-dev:fix/6-empty-puts

Conversation

@crossi-dev

Copy link
Copy Markdown

Fixes #6

Problem

Terminalwire::Server::Resource::STDOUT#puts is declared with a required argument:

def puts(data)
  command("print_line", data: data)
end

So calling context.puts with no arguments raises ArgumentError: wrong number of arguments (given 0, expected 1). Ruby's stdlib puts with no args is valid and prints a blank line, so this is a surprising crash for an otherwise drop-in API.

Fix

Make the argument optional and coerce with to_s, matching stdlib puts semantics (no args / nil → blank line):

def puts(data = nil)
  command("print_line", data: data.to_s)
end

One-line change, plus two RSpec cases covering the no-arg and nil paths.

Verified

The repo's integration suite uses pty (Linux pseudoterminal), which I can't run on my machine, so I verified the method logic directly:

BEFORE (def puts(data)):
  puts("Hello")  → "Hello"   PASS
  puts()         → ArgumentError: wrong number of arguments (given 0, expected 1)   ← bug
  puts(nil)      → ""         PASS

AFTER (def puts(data = nil)):
  puts("Hello")  → "Hello"   PASS
  puts()         → ""         PASS
  puts(nil)      → ""         PASS

Came across Terminalwire and noticed #6 had been open a while, so I went ahead and fixed it. No strings attached — I'm with Choreless and we like contributing real fixes to projects we use. If it's useful and you ever want a hand with something larger, happy to help.

— Charles

Ruby stdlib puts() with no args prints a blank line. The server-side
STDOUT resource required a positional data argument, raising
ArgumentError when called as puts().

Change def puts(data) to def puts(data = nil) and call .to_s on data
so nil coerces to the empty string, producing the expected blank line.

Closes terminalwire#6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Empty Puts Crashes

1 participant