Bundler cannot continue; error parsing 'Gemfile': (<unknown>)

Louis Gillette picture Louis Gillette · Mar 23, 2016 · Viewed 7k times · Source

While using these installation instructions, https://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_30x_on_Ubuntu_1404_with_Apache2_Phusion_Passenger_MySQL_Subversion_and_Git_%28Gitolite%29,

I ran into an issues when I performed the following command

bundle install --without development test postgresql sqlite

And got the following error.

redmine@zaps-VirtualBox:~/redmine$ bundle install --without development test postgresql sqlite

[!] There was an error parsing `Gemfile`: (<unknown>): found character that cannot start any token while scanning for the next token at line 10 column 13. Bundler cannot continue.

 #  from /opt/redmine/redmine-3.0.4/Gemfile:57
 #  -------------------------------------------
 #    database_config = YAML::load(ERB.new(IO.read(database_file)).result)
 #    adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
 #  -------------------------------------------

I've checked YAML syntax with this tool, http://www.yamllint.com/ , but nothing shakes out.

As seen in the code, I commented out the line in question and simply rewrote it (an IT fellow suggested tab syntax or white spaces as the issue) also to no avail.

My Gemfile is as follows;

if Gem::Version.new(Bundler::VERSION) < Gem::Version.new('1.5.0')
  abort "Redmine requires Bundler 1.5.0 or higher (you're using #{Bundler::VERSION}).\nPlease update with 'gem update bundler'." 
end

gem "rails", "4.2.3"
gem "jquery-rails", "~> 3.1.3"
gem "coderay", "~> 1.1.0"
gem "builder", ">= 3.0.4"
gem "request_store", "1.0.5"
gem "mime-types"
gem "protected_attributes"
gem "actionpack-action_caching"
gem "actionpack-xml_parser"

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :x64_mingw, :mswin, :jruby]
gem "rbpdf", "~> 1.18.6"

# Optional gem for LDAP authentication
group :ldap do
  gem "net-ldap", "~> 0.3.1"
end

# Optional gem for OpenID authentication
group :openid do
  gem "ruby-openid", "~> 2.3.0", :require => "openid"
  gem "rack-openid"
end

platforms :mri, :mingw, :x64_mingw do
  # Optional gem for exporting the gantt to a PNG file, not supported with jruby
  group :rmagick do
    gem "rmagick", "~> 2.13.4"
  end

  # Optional Markdown support, not for JRuby
  group :markdown do
    gem "redcarpet", "~> 3.1.2"
  end
end

platforms :jruby do
  # jruby-openssl is bundled with JRuby 1.7.0
  gem "jruby-openssl" if Object.const_defined?(:JRUBY_VERSION) && JRUBY_VERSION < '1.7.0'
  gem "activerecord-jdbc-adapter", "~> 1.3.2"
end

# Include database gems for the adapters found in the database
# configuration file
require 'erb'
require 'yaml'
database_file = File.join(File.dirname(__FILE__), "config/database.yml")
if File.exist?(database_file)
#  database_config = YAML::load(ERB.new(IO.read(database_file)).result)
  database_config = YAML::load(ERB.new(IO.read(database_file)).result)
  adapters = database_config.values.map {|c| c['adapter']}.compact.uniq
  if adapters.any?
    adapters.each do |adapter|
      case adapter
      when 'mysql2'
        gem "mysql2", "~> 0.3.11", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when 'mysql'
        gem "activerecord-jdbcmysql-adapter", :platforms => :jruby
      when /postgresql/
        gem "pg", "~> 0.17.1", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-jdbcpostgresql-adapter", :platforms => :jruby
      when /sqlite3/
        gem "sqlite3", :platforms => [:mri, :mingw, :x64_mingw]
        gem "jdbc-sqlite3", ">= 3.8.10.1", :platforms => :jruby
        gem "activerecord-jdbcsqlite3-adapter", :platforms => :jruby
      when /sqlserver/
        gem "tiny_tds", "~> 0.6.2", :platforms => [:mri, :mingw, :x64_mingw]
        gem "activerecord-sqlserver-adapter", :platforms => [:mri, :mingw, :x64_mingw]
      else
        warn("Unknown database adapter `#{adapter}` found in config/database.yml, use Gemfile.local to load your own database gems")
      end
    end
  else
    warn("No adapter found in config/database.yml, please configure it first")
  end
else
  warn("Please configure your config/database.yml first")
end

group :development do
  gem "rdoc", ">= 2.4.2"
  gem "yard"
end

group :test do
  gem "minitest"
  gem "rails-dom-testing"
  gem "mocha"
  gem "simplecov", "~> 0.9.1", :require => false
  # For running UI tests
  gem "capybara"
  gem "selenium-webdriver"
end

local_gemfile = File.join(File.dirname(__FILE__), "Gemfile.local")
if File.exists?(local_gemfile)
  eval_gemfile local_gemfile
end

# Load plugins' Gemfiles
Dir.glob File.expand_path("../plugins/*/{Gemfile,PluginGemfile}", __FILE__) do |file|
  eval_gemfile file
end

What will resolve the conflict? Is more information required? Where can I find information about 'token's in the future?

Answer

Holger Just picture Holger Just · Mar 23, 2016

Redmine loads the config/database.yml file from the Gemfile to determine the correct gem to require to access your configured database. Now, it seems your database.yml is invalid and can't be loaded. Thus, bundler can't finish installing the required gems.

To resolve this issue, ensure that your config/database.yml is syntactically correct YAML. Check at or around line 10, column 13 in your database.yml file for errors.