piotrmurach / tty-command

Execute shell commands with pretty output logging and capture stdout, stderr and exit status.
https://ttytoolkit.org
MIT License
400 stars 34 forks source link

bytesize on nil #22

Closed ondra-m closed 8 years ago

ondra-m commented 8 years ago

I have error NoMethodError: undefined method bytesize for nil:NilClass on

  cmd = TTY::Command.new
  cmd.run "wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz"

Problem is that value[offset..-1] return nil. Offsett is equal to value size.

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.2%) to 91.925% when pulling fd4bf200cf77511dbf10b5486f3f26827998509c on ondra-m:bytesize-on-nil into a3b9e24ec2f07336383f11d6f7a95622b441bfa2 on piotrmurach:master.

piotrmurach commented 8 years ago

Hi Ondrej, thanks for fixing the bug, would you mind creating a test case to trap this problem in truncator_spec?

coveralls commented 8 years ago

Coverage Status

Coverage increased (+0.2%) to 91.925% when pulling 9eed29c0273922645a04069b8d88070fbc15296d on ondra-m:bytesize-on-nil into a3b9e24ec2f07336383f11d6f7a95622b441bfa2 on piotrmurach:master.

ondra-m commented 8 years ago

I think this is just workaround. Would not it be better to

  1. Use .byteslice instead of .[]
  2. Or use .[] but without .bytesize (just .size)
piotrmurach commented 8 years ago

Thanks for providing test case and suggestions for fixing the issue, much appreciated!

Decided to go with the first option and released v0.2.0. Enjoy!