rubyrubygemsgemfileroosorbet

How to fix srb irb update error using gem Roo? or any option how to skip roo from type checking?


I have data pipeline that needs to work with excel xls. I use gem roo for reading xlsx and Push to some API endpoint. I'm starting the project use gem sorbet. Execute srb init and it works. But when I add gem roo, it becomes error.

How can I tell sorbet to skip checking roo gem only? or how can I fix this error?

Here my Gemfile list.

# frozen_string_literal: true

# typed: ignore

source 'https://rubygems.org'

gem 'activesupport', '< 5.1'
gem 'aws-record', '~> 2'
gem 'aws-sdk-s3', '~> 1'
gem 'faraday'
gem 'pry'
gem 'roo', '2.7.1'
gem 'rspec', group: :development
gem 'rubocop', group: :development
gem 'sorbet', group: :development
gem 'sorbet-runtime'
gem 'uuidtools'

And this is the error traceback from sorbet

Generating: sorbet/config
Reusing existing config file: sorbet/config
Generating: sorbet/rbi/sorbet-typed/
Generating: sorbet/rbi/gems/
Traceback (most recent call last):
    14: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:234:in `<main>'
    13: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:196:in `main'
    12: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:118:in `init'
    11: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/bin/srb-rbi:229:in `block in make_step'
    10: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint.rb:38:in `main'
     9: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint/tracer.rb:70:in `trace'
     8: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem-generator-tracepoint.rb:39:in `block in main'
     7: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/require_everything.rb:19:in `require_everything'
     6: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/require_everything.rb:39:in `load_bundler'
     5: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:579:in `require_all_gems'
     4: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:579:in `each'
     3: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:581:in `block in require_all_gems'
     2: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:557:in `require_gem'
     1: from /Users/ruby/.rvm/gems/ruby-2.5.1/gems/sorbet-0.4.4540/lib/gem_loader.rb:208:in `block in <class:GemLoader>'
/Users/ruby/.rvm/gems/ruby-2.5.1/gems/roo-2.7.1/lib/roo.rb:24:in `const_missing': Excel support has been extracted to roo-xls due to its dependency on the GPL'd spreadsheet gem. Install roo-xls to use Roo::Excel. (RuntimeError)

Here my lambda_function.rb

# frozen_string_literal: true

# typed: true
require 'aws-sdk-s3'
require 'json'
require 'pry'
require 'roo'

def lambda_handler(event:, context:)
  response = {
    statusCode: 200,
    body: {
      event: event['filename'],
      context: context
    }
  }

  response
end

event = {
  event: {
    operation: 'echo',
    message: 'Hello world!',
    filename: './penjualan_per_barang_190612145614.xlsx'
  },
  context: {}
}

lambda_handler(event)

I expect the srb init would return success. If there any help, it would be great.


Solution

  • This looks like a bug in Sorbet. I've created a fix for it here:

    https://github.com/sorbet/sorbet/pull/1454

    I'm not sure how you should work around it in the mean time other than not depend on 'roo'.