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

Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8 #57

Closed
robd opened this issue Jul 22, 2015 · 3 comments
Milestone

Comments

@robd
Copy link
Contributor

robd commented Jul 22, 2015

I see the error below [1] from the console truncation code on master. In certain circumstances, the string coming back from net ssh seems to be ASCII-8BIT encoded (this happens when I am logging a string containing a left quotation mark ), and this causes appending the ellipsis to fail, I guess because it cannot be converted into ASCII-8BIT.

I added some logging like this to the truncate_to_console_width method:

string.chop! while strip_ascii_color(string).length >= width
more_string = "…\e[0m"
p [string.encoding, more_string.encoding]
string << more_string

Most of the strings coming back from the server give this debug:
[#<Encoding:UTF-8>, #<Encoding:UTF-8>]

It is just the one containing the quotation mark which gives this debug:
[#<Encoding:ASCII-8BIT>, #<Encoding:UTF-8>]

I'm not sure why net ssh is returning ASCII-8BIT in this case or what the right thing to do is. Changing from an ellipsis to 3 periods (...) fixes the problem, I guess because they can be converted to ASCII-8BIT. I'm not sure what is going on here, but I thought I'd make a note of it since it appears to be caused by Airbrussh truncation.

[1]

SSHKit::Runner::ExecuteError: Exception while executing as xxxx: incompatible character encodings: ASCII-8BIT and UTF-8
sshkit-c840d4f63f41/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
sshkit-c840d4f63f41/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Encoding::CompatibilityError: incompatible character encodings: ASCII-8BIT and UTF-8
airbrussh-6191c3937d5d/lib/airbrussh/console.rb:48:in `truncate_to_console_width'
airbrussh-6191c3937d5d/lib/airbrussh/console.rb:26:in `print_line'
airbrussh-6191c3937d5d/lib/airbrussh/console_formatter.rb:112:in `print_line'
airbrussh-6191c3937d5d/lib/airbrussh/console_formatter.rb:117:in `print_indented_line'
airbrussh-6191c3937d5d/lib/airbrussh/console_formatter.rb:42:in `block in log_command_data'
airbrussh-6191c3937d5d/lib/airbrussh/console_formatter.rb:41:in `each_line'
airbrussh-6191c3937d5d/lib/airbrussh/console_formatter.rb:41:in `log_command_data'
airbrussh-6191c3937d5d/lib/airbrussh/delegating_formatter.rb:25:in `public_send'
airbrussh-6191c3937d5d/lib/airbrussh/delegating_formatter.rb:25:in `block (3 levels) in <class:DelegatingFormatter>'
airbrussh-6191c3937d5d/lib/airbrussh/delegating_formatter.rb:25:in `map'
airbrussh-6191c3937d5d/lib/airbrussh/delegating_formatter.rb:25:in `block (2 levels) in <class:DelegatingFormatter>'
sshkit-c840d4f63f41/lib/sshkit/backends/netssh.rb:93:in `block (4 levels) in execute_command'
net-ssh-2.9.2/lib/net/ssh/connection/channel.rb:569:in `call'
@mattbrictson
Copy link
Owner

Thanks for the detailed report. I'll probably work on a solution later today. If you get to it first, add a comment here so that I know not to duplicate your efforts.

@robd
Copy link
Contributor Author

robd commented Jul 22, 2015

Ah that would be great if you have time - I won't have a chance to look at this for a few days. For the moment, I just disabled truncation, which is fine as a workaround.

@mattbrictson
Copy link
Owner

Fixed via #58.

@mattbrictson mattbrictson added this to the 0.6.1 milestone Jul 22, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants