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

Device names with apostrophes cause invalid byte sequence in US-ASCII (ArgumentError) #74

Closed
coquifrogs opened this issue Nov 14, 2014 · 7 comments

Comments

@coquifrogs
Copy link

OS X 10.10 Xcode 6.1

$ xcrun instruments -s devices

Known Devices:
John’s MacBook Pro (3) [515DA020-6292-5EC9-9489-93B2BDCFBDED]

Note the apostrophe is UTF-8.

Error stack trace is:

invalid byte sequence in US-ASCII (ArgumentError)
/Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/xctools.rb:152:in split' /Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/xctools.rb:152:inblock (2 levels) in instruments'
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open3.rb:217:in popen_run' /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/2.0.0/open3.rb:99:inpopen3'
/Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/xctools.rb:150:in block in instruments' /Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/xctools.rb:155:incall'
/Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/xctools.rb:155:in instruments' /Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/sim_control.rb:863:insim_details'
/Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/sim_control.rb:290:in enable_accessibility_on_sims' /Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/core.rb:95:inrun_with_options'
/Library/Ruby/Gems/2.0.0/gems/run_loop-1.1.0/lib/run_loop/core.rb:690:in run' /Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.11.4/lib/calabash-cucumber/launcher.rb:732:inblock in new_run_loop'
/Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.11.4/lib/calabash-cucumber/launcher.rb:730:in times' /Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.11.4/lib/calabash-cucumber/launcher.rb:730:innew_run_loop'
/Library/Ruby/Gems/2.0.0/gems/calabash-cucumber-0.11.4/lib/calabash-cucumber/launcher.rb:605:in `relaunch'

@coquifrogs
Copy link
Author

I'm aware this is because the default external encoding is US-ASCII, but It would be nice if that didn't matter or was maybe mentioned somewhere.

@jmoody
Copy link
Contributor

jmoody commented Nov 14, 2014

@coquifrogs Thanks for reporting. Grrr.

I can't decide how and where to solve this problem.

  • Is the gem at fault? Is it not configured correctly for UTF-8?
  • Should I force ASCII encoding when parsing the output of instruments?
  • Is it the fault of the Apple installed ruby?

@michaelkirk @svevang

  • See if this can be reproduced locally in rbenv.

@michaelkirk
Copy link

My first thought is that it seems like the gem is at fault - it's trying to parse a non-ascii string of bytes as if it were ascii.

@svevang
Copy link
Contributor

svevang commented Nov 15, 2014

Hi @coquifrogs, can you paste the output of the locale command? For reference here is my output:

○ → locale
LANG="en_US.UTF-8"
LC_COLLATE="en_US.UTF-8"
LC_CTYPE="en_US.UTF-8"
LC_MESSAGES="en_US.UTF-8"
LC_MONETARY="en_US.UTF-8"
LC_NUMERIC="en_US.UTF-8"
LC_TIME="en_US.UTF-8"
LC_ALL=

If your locale is set to ASCII you are going to have trouble with software like ruby parsing standard input that is encoded as UTF-8. Without digging too deeply, it looks like ruby uses the system's locale to identify the character encoding of stdin/stdout.

@jmoody
Copy link
Contributor

jmoody commented Nov 19, 2014

@coquifrogs

I don't think it is reasonable for run-loop to try to support any encoding other than the default ruby and MacOS encoding. We would have to clean every string we read from stdout and stderr. At this point, we don't have the resources to do so.

I think you already know the workarounds, but I will mention them in case someone else bumps into this issue.

  • Change the system locale to UTF-8.
  • Rename your machine with ASCII characters.

I am on thin ice here; I do not have a firm understand of how encodings and locales interact on MacOS.

I'm aware this is because the default external encoding is US-ASCII, but It would be nice if that didn't matter or was maybe mentioned somewhere.

If you write some documentation, I will try to figure out some place to put it.

@jmoody jmoody closed this as completed Nov 19, 2014
@coquifrogs
Copy link
Author

It may not be the default for OS X. I can't confirm that, but other people have posted on Stackoverflow about it on Lion even. Since OS X by default names your machine with that UTF-8 apostrophe it is a likely error.

The workarounds given should be fine, but the error that occurs is not helpful in figuring out the problem.

Here's the output of running locale on my machine:

jcannon@jcannon-mbp: ~

locale
LANG=
LC_COLLATE="C"
LC_CTYPE="C"
LC_MESSAGES="C"
LC_MONETARY="C"
LC_NUMERIC="C"
LC_TIME="C"
LC_ALL=

@jmoody
Copy link
Contributor

jmoody commented Sep 11, 2015

@coquifrogs

At long last, I have reproduced and I now understand the error of my ways.

Working on a fix.

@michaelkirk @svevang @TobiasRoikjer

The problem is that read, which we use everywhere, always returns a string with ASCII-8BIT encoding.

http://ruby-doc.org/core-2.2.2/IO.html#method-i-read

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

No branches or pull requests

4 participants