4

Here's the stack: Sproutcore 1.0.1046. Ruby 1.9.1, in RVM. Thin 1.2.7. Thor 0.13.8. Rack 1.2.1. Eventmachine 0.12.10. Erubis 2.6.6.

When I start the sc-server on any application, my first request to this server produces this in the console log:

ArgumentError: invalid byte sequence in US-ASCII

...followed by this stack trace. (I've listed gems which appear in the stack trace above, but there's a complete gemset list in the same gist as the stack trace.)

Research on the error message points out that this is a common problem with Ruby 1.9, but the stack trace suggests that the problem is in one of the gems somewhere.

I have:

  • Upgraded my OS (Mac OS X 10.5 to 10.6) in order to get the latest gcc Apple provides.
  • Reinstalled RVM.
  • Reinstalled Ruby.
  • Reinstalled all the relevant gems.

And yet I still have this problem on one system, but not on another. (N.B. there are several devs working on this code, and I'm the only one seeing this problem. I'm 99% certain it's not our code.) I guess what I'm saying is that I've cleared and rebuilt a lot of gems to try to isolate or remove this glitch, and yet I still haven't gotten rid of it.

Where should I look next?

5 Answers 5

5

You have some special setting in your bash environment that is setting ruby to use US-ASCII , this happened to me trying to execute sc-server from a remote terminal... I'm not really sure what it is, but it doesn't use UTF-8 and that's when it runs into trouble.

2
  • You can see what's in your environment variables by running the 'env' command from bash. Or by examining the ENV hash in Ruby.
    – AboutRuby
    Aug 30, 2010 at 7:15
  • 2
    THANK YOU. I checked the environments on the two systems, and the one that worked had several en_US.UTF-8 settings, and the one that didn't has several en_US.us-ascii settings. The LC_CTYPE environment variable seems to be the key, because setting that in my .bash_profile seemed to solve the problem without changing any others.
    – pjmorse
    Aug 30, 2010 at 15:03
2

You can probably also change Encoding.default_external

1

Thanks so much for the Encoding.default_external suggestion. I was having the same problem, despite correctly set magic comments and environment variables. In Rails 2.3.9 I added this before_filter in application_controller.rb, resolved the issue:

def set_encoding
  Encoding.default_external = 'UTF-8'
end
1
  • This fixed problems in my Mac OS X Lion dev environment.
    – richardsun
    Dec 18, 2011 at 1:27
1

I had the same issue with RSS Feeds that I was displaying in a Rails 2.3.8 app with Ruby 1.9.2. My issue wasn't solved by the application_controller.rb before_filter technique mentioned here. The fix was to put the following into "RAILS_ROOT/config/initializers/string_encodings.rb":

Encoding.default_external = 'UTF-8'

That worked for me site-wide, instead of on a controller level.

1
  • I'm sure that would work for a Rails app, but the one I was having this problem with wasn't a Rails app.
    – pjmorse
    Mar 24, 2011 at 2:21
1

In my case the ArgumentError occurred during a Capistrano deploy call that envolves ruby's net-ssh (ruby 1.9.2p290, net-ssh 2.3.0). None of the solutions afore mentioned worked and none of the other reasons I've read about so far: i.e. "strange character in key file", etc..

Finally, I found a none ASCII-character in a comment(!) line in my ASCII encoded ~/.ssh/config file. BINGO!

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.