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

'invalid byte sequence in US-ASCII' #48

Open
strega-nil opened this issue Jan 29, 2020 · 5 comments
Open

'invalid byte sequence in US-ASCII' #48

strega-nil opened this issue Jan 29, 2020 · 5 comments

Comments

@strega-nil
Copy link

When attempting to create a virtualbox mac box, for Catalina, from Catalina, the following issue occurs:

% sudo macinbox --box-format virtualbox --name vcpkg-eg-mac-base --disk 220 --memory 12000 --cpu 5 --full Vagrant --short vagrant --password vagrant --no-gui --no-auto-login --installer /Applications/Install\ macOS\ Catalina.app

Password:
_ Checking macOS versions...
_ Creating image from installer...
  + Creating and attaching wrapper disk image...

_ Cleaning up...
Traceback (most recent call last):                                                                                                                                                                        15: from /usr/local/bin/macinbox:23:in `<main>'                                                                                                                                                   14: from /usr/local/bin/macinbox:23:in `load'                                                                                                                                                     13: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/exe/macinbox:5:in `<top (required)>'                                                                                                        12: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/cli.rb:19:in `run!'                                                                                                            11: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/cli.rb:138:in `start'                                                                                                          10: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/cli.rb:138:in `chdir'                                                                                                           9: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/cli.rb:144:in `block in start'                                                                                                  8: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/logger.rb:17:in `info'                                                                                                          7: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/cli.rb:145:in `block (2 levels) in start'                                                                                       6: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/actions/create_image_from_installer.rb:45:in `run'                                                                              5: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/actions/create_image_from_installer.rb:72:in `create_wrapper_image'                                                             4: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/logger.rb:17:in `info'                                                                                                          3: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/actions/create_image_from_installer.rb:77:in `block in create_wrapper_image'                                                    2: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/virtual_disk.rb:50:in `attach'                                                                                                  1: from /Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/virtual_disk.rb:20:in `set_devices'
/Library/Ruby/Gems/2.6.0/gems/macinbox-4.0.0/lib/macinbox/virtual_disk.rb:20:in `[]': invalid byte sequence in US-ASCII (ArgumentError)

When I set LANGUAGE = LC_ALL = LANG = 'en_US.UTF-8', then the process succeeds; is there a way to make sure it always runs in utf-8 mode?

@bacongravy
Copy link
Owner

Hello @strega-nil, thank you for reporting this issue. My LANG is usually set to en_US.UTF-8 and probably explains why I've never seen this before.

It should be straightforward to override the LANG in the macinbox process to always be UTF8. I'll work on reproducing this issue and then identify a fix.

@strega-nil
Copy link
Author

strega-nil commented Jan 31, 2020

Thanks @bacongravy!!!

bitmoji

@bacongravy
Copy link
Owner

I haven't been able to reproduce this issue, so I'm not sure if the change I had in mind fixes it. I was able to create a Terminal profile with the language set to "Western (ASCII)" which resulted in me having LANG=en_US.US-ASCII, but macinbox didn't fail when I ran it.

@bacongravy
Copy link
Owner

My idea was to put ENV['LANG'] = 'en_US.UTF-8' in cli.rb near the top of the start method.

@adamwolf
Copy link

I ran into this, and I have a few more details.

  1. I ran into this when running this as root. As a user, I had LANG and LC_ALL set already, but as root, I did not. I know I didn't do anything hinky with those because this was pretty soon after a fresh install.

  2. I tried the ENV['LANG'] thing in cli.rb, and it didn't work, which led me to investigate. The issue seems to actually be with the encoding that Ruby uses in the io Popen calls in Task. You could override the encoding there, with :encoding.I didn't know how unicode things worked in Ruby, actually, so I looked it up. (mostly at https://docs.ruby-lang.org/en/2.1.0/Encoding.html)

By default Ruby sets the external encoding of an IO object to the default external encoding. The default external encoding is set by locale encoding or the interpreter -E option. ::default_external returns the current value of the external encoding.

The default external encoding may also be set through ::default_external=, but you should not do this as strings created before and after the change will have inconsistent encodings. Instead use ruby -E to invoke ruby with the correct external encoding.

I am not a Ruby expert, and I am not a macinbox expert at all, but my gut feeling would be to detect LC_ALL and LC_LANG being empty, maybe next to where you detect if you were ran with sudo. If this is mainly happening to folks who are running this as root, well... don't do that :)

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

3 participants