Tag: Rails

Ruby Geokit invalid trailing UTF-8 octet at line 1 column 1 fix

Today I've encountered a small problem with Geokit:

Geokit::Geocoders::IpGeocoder.do_geocode('31.174.47.24')
Psych::SyntaxError: (<unknown>): invalid trailing UTF-8 octet at line 1 column 1

I don't have time (because it happened on production) to investigate this issue, so I've developed a quick temporary fix, which just removes invalid characters:

# Temporary workaround for crazy not UTF-8 characters in response
module Geokit
  module Geocoders
    class IpGeocoder
      require 'iconv'

      def self.parse_body(body)
        yaml = YAML.load(Iconv.conv('ASCII//IGNORE', 'UTF8', body))
        res = GeoLoc.new
        res.provider = 'hostip'
        res.city, res.state = yaml['City'].split(', ')
        country, res.country_code = yaml['Country'].split(' (')
        res.lat = yaml['Latitude']
        res.lng = yaml['Longitude']
        res.country_code.chop!
        res.success = !(res.city =~ /\(.+\)/)
        res
      end
    end
  end
end

No source for ruby-1.9.3-p374 provided with debugger-ruby_core_source gem

After updating Ruby to 1.9.3-374 debugger stopped working:

Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.

        /home/mencio/.rvm/rubies/ruby-1.9.3-p374/bin/ruby extconf.rb 
checking for vm_core.h... no
checking for vm_core.h... no
Makefile creation failed
**************************************************************************
No source for ruby-1.9.3-p374 provided with debugger-ruby_core_source gem.
**************************************************************************
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
	--with-opt-dir
	--with-opt-include
	--without-opt-include=${opt-dir}/include
	--with-opt-lib
	--without-opt-lib=${opt-dir}/lib
	--with-make-prog
	--without-make-prog
	--srcdir=.
	--curdir
	--ruby=/home/mencio/.rvm/rubies/ruby-1.9.3-p374/bin/ruby
	--with-ruby-dir
	--without-ruby-dir
	--with-ruby-include
	--without-ruby-include=${ruby-dir}/include
	--with-ruby-lib
	--without-ruby-lib=${ruby-dir}/lib


Gem files will remain installed in /path/gems/debugger-linecache-1.1.2 for inspection.
Results logged to /path/gems/debugger-linecache-1.1.2/ext/trace_nums/gem_make.out
An error occurred while installing debugger-linecache (1.1.2), and Bundler cannot continue.
Make sure that `gem install debugger-linecache -v '1.1.2'` succeeds before bundling.

How can we fix this?

gem install debugger-linecache -v '1.1.2' -- --with-ruby-include=\$rvm_path/src/ruby-1.9.3-p374

And that's all!

Copyright © 2025 Closer to Code

Theme by Anders NorenUp ↑