macinbox
macinbox copied to clipboard
'invalid byte sequence in US-ASCII'
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?
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.
Thanks @bacongravy!!!
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.
My idea was to put ENV['LANG'] = 'en_US.UTF-8'
in cli.rb
near the top of the start
method.
I ran into this, and I have a few more details.
-
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.
-
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 :)