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

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.

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'.

Related

uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionManagement

Im currently working on a sinatra app, and im having a trouble regarding postgresql connection to sinatra, im try to execute this command:
rake db:create
to create the database but it throws this error.
C:\Users\John\Documents\Registration_Sinatra>rake db:create
rake aborted!
NameError: uninitialized constant ActiveRecord::ConnectionAdapters::ConnectionManagement
C:/Users/John/Documents/Registration_Sinatra/app/app.rb:2:in `<top (required)>'
C:/Users/John/Documents/Registration_Sinatra/Rakefile:1:in `<top (required)>'
LoadError: cannot load such file -- sinatra/activerecord
C:/Users/John/Documents/Registration_Sinatra/app/app.rb:2:in `<top (required)>'
C:/Users/John/Documents/Registration_Sinatra/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)
this is my app.rb
require 'sinatra'
require 'sinatra/activerecord'
require 'pg'
require './config/environments'
class RegistrationSinatra < ActiveRecord::Base
end
get '/' do
erb :index
end
this is my environments.rb
configure :development do
#DEFAULT_CONN = {database: 'development_registration_sinatra', user: 'postgres', password: 'secret123', host: 'localhost'}
db = URI.parse(ENV['DATABASE_URL'] || "postgres://#{#DEFAULT_CONN[:host]}/#{#DEFAULT_CONN[:database]}?user=#{#DEFAULT_CONN[:user]}")
ActiveRecord::Base.establish_connection(
:adapter => db.scheme == 'postgres' ? 'postgresql' : db.scheme,
:host => #DEFAULT_CONN[:host],
:username => #DEFAULT_CONN[:user],
:password => #DEFAULT_CONN[:password],
:database => db.path[1..-1],
:encoding => 'utf8')
end
this is my gemfile
source 'https://rubygems.org'
ruby "2.2.2"
gem 'sinatra'
gem 'activerecord'
gem 'sinatra-activerecord'
gem 'tux'
gem 'pg'
and my Rakefile
require './app/app'
require 'sinatra/activerecord/rake'
hope you guys can pin point what's wrong with my sample app so i can progress thanks.
Here is the solution: https://github.com/janko-m/sinatra-activerecord/pull/66
In your Gemfile, add:
gem "activerecord", "< 5.0.0"
run bundle update and it will work.

Using gems in Ruby *basic*

I'm a complete newbie.
I have a gem I want to install and use, let's say it's this one:
https://rubygems.org/gems/linkedindata/versions/0.0.22
I'm using cmd:
gem install linkedindata
#1 gem installed
After that I add it to my gemfile:
gemrat 'linkedindata'
#gem 'linkedindata', '0.0.22' added to your Gemfile.
Now to use linkedindata I have to create a new object and specify my search. So I do:
**test.rb**
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
Now I run the test.rb from command prompt:
test.rb:1:in `<main>': undefined local variable or meth
od `linkedindata' for main:Object (NameError)
So, I obviously need to require the 'linkedindata' gem here. I added:
**test.rb**
require 'LinkedinData'
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
I get the following error:
C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `re
quire': cannot load such file -- linkedin-scraper (LoadError)
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:54:in `require'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
data.rb:1:in `<top (required)>'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:128:in `require'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:128:in `rescue in require'
from C:/Ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require
.rb:39:in `require'
from C:/Users/test.rb:1:in `<main>'
Am I doing something fundamentally wrong here? Or is there a problem with this gem?
UPDATE
The problem was within the gem, see Doon's answer below.
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
++++ correct how the gem requires "linkedin_scraper" in linkedindata.rb
Next problem occurs
C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin.rb:6:in `<cl
ass:Profile>': uninitialized constant Linkedin::Profile::ProxyManager (NameError
)
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
.rb:5:in `<module:Linkedin>'
from C:/Ruby22/lib/ruby/gems/2.2.0/gems/linkedindata-0.0.22/lib/linkedin
.rb:4:in `<top (required)>'
from linkedinscrape.rb:4:in `require'
from linkedinscrape.rb:4:in `<main>'
Which obviously has to do with the proxy settings. The list:
**proxylist.txt**
220.248.224.242:8089
165.139.179.225:8080
54.207.114.172:3333
190.63.174.246:8081
The way I load it:
l = LinkedinData.new(1, "c:/users/proxylist.txt")
As you are using a Gemfile, you are using bundler. In your script you will need to include rubygems and bundler to make it work. Try this
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "c:/users/proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
You have run bundle install, sorry not familiar with gemrat, so not sure how much it does for you.
if you are not actually using bundler, just remove require 'bundler/setup' from the code above, you will still need to require rubygems though in your script.
in looks like the gem itself is kind of broken in the way it declare dependencies, and the other gems that it relies on. I appear to be able to make it work as follows:
Gemfile:
source 'https://rubygems.org'
gem 'linkedin-scraper'
gem 'linkedindata'
gem 'generalscraper'
gem 'uploadconvert'
gem 'docsplit'
gem 'crack'
gem 'pry'
gem 'activesupport'
gem 'selenium-webdriver'
It also appears that it the linkedin-scraper needs to required as linkedin_scraper but not sure why that is. So editing.
{GEMPATH}/linkedindata-0.0.22/lib/linkedindata.rb to require 'linkedin_scraper' as opposed to require 'linkedin-scraper' seems to make it work.
So with the above changes and using bundler
require 'rubygems'
require 'bundler/setup'
require 'linkedindata'
l = LinkedinData.new(1, "proxylist.txt", true, true)
searchTerms = ['First', 'Second', 'Third']
l.getByKeywords(searchTerms)
now runs (I don't have a proxylist.txt so it blows up looking for it, but it doesn't get anymore library errors).

Bundler.require(:default) fails in Rubinius

I have a very simple app, which i tried to run with Rubinius:
Gemfile:
source 'https://rubygems.org
gem 'rake'
gem 'tiny_tds'
gem 'sequel'
lib/database.rb:
require "rubygems"
require "bundler/setup"
Bundler.require(:default)
DB = Sequel.tinytds(:host => 'SQL2012', :user => "Rails", :password => "xxx", :database => "RailsTest")
test/connection_test.rb:
require_relative "../lib/database"
DB.fetch("SELECT TOP 10 * FROM User") do |row|
puts row.to_s
end
Rakefile:
require 'rubygems'
require 'rake'
require 'rake/clean'
require 'rake/testtask'
Rake::TestTask.new do |t|
t.test_files = FileList['test/**/*.rb']
end
task :default => :test
This runs fine with MRI 1.9.3 and MRI 2.1.0
but fails with rbx 2.2.2 :
klaus#rails-dev:$ rake test
An exception occurred running /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:
no such file to load -- bigdecimal (LoadError)
Backtrace:
Rubinius::CodeLoader#load_error at kernel/common/code_loader.rb:440
Rubinius::CodeLoader#resolve_require_path at kernel/common/code_loader.rb:423
{ } in Rubinius::CodeLoader#require at kernel/common/code_loader.rb:103
Rubinius.synchronize at kernel/bootstrap/rubinius.rb:137
Rubinius::CodeLoader#require at kernel/common/code_loader.rb:102
Rubinius::CodeLoader.require at kernel/common/code_loader.rb:237
Kernel(Object)#require at kernel/common/kernel.rb:705
Object#__script__ at /home2/klaus/.rvm/gems/rbx-2.2.2/gems/tiny_tds-0.6.1/lib/tiny_tds.rb:3
Rubinius::CodeLoader.require at kernel/common/code_loader.rb:243
Kernel.require at kernel/common/kernel.rb:705
{ } in Bundler::Runtime#require at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:76
Array#each at kernel/bootstrap/array.rb:66
{ } in Bundler::Runtime#require at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:72
Array#each at kernel/bootstrap/array.rb:66
Bundler::Runtime#require at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/bundler-1.5.2/lib/bundler/runtime.rb:61
Bundler.require at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/bundler-1.5.2/lib/bundler.rb:131
Object#__script__ at lib/database.rb:4
Rubinius::CodeLoader.require at kernel/common/code_loader.rb:243
Rubinius::CodeLoader.require_relative at kernel/common/code_loader.rb:143
Kernel(Object)#require_relative at kernel/common/kernel.rb:711
Object#__script__ at test/connection_test.rb:2
Rubinius::CodeLoader.require at kernel/common/code_loader.rb:243
Kernel(Object)#gem_original_require (require) at kernel/common/kernel.rb:705
Kernel(Object)#require at /home2/klaus/.rvm/rubies/rbx-2.2.2/site/rubygems/core_ext/kernel_require.rb:55
{ } in Object#__script__ at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:15
{ } in Enumerable(Array)#find_all at kernel/common/enumerable.rb:432
Array#each at kernel/bootstrap/array.rb:66
Enumerable(Array)#select (find_all) at kernel/common/enumerable.rb:430
Object#__script__ at /home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/rake-10.1.1/lib/rake/rake_test_loader.rb:4
Rubinius::CodeLoader#load_script at kernel/delta/code_loader.rb:66
Rubinius::CodeLoader.load_script at kernel/delta/code_loader.rb:200
Rubinius::Loader#script at kernel/loader.rb:649
Rubinius::Loader#main at kernel/loader.rb:831
rake aborted!
Command failed with status (1): [ruby -I"lib" -I"/home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/rake-10.1.1/lib" "/home2/klaus/.rvm/gems/rbx-2.2.2#global/gems/rake-10.1.1/lib/rake/rake_test_loader.rb" "test/connection_test.rb" ]
kernel/bootstrap/proc.rb:20:in `call'
kernel/bootstrap/proc.rb:20:in `call'
kernel/bootstrap/array.rb:66:in `each'
kernel/bootstrap/array.rb:66:in `each'
kernel/common/kernel.rb:447:in `load'
kernel/delta/code_loader.rb:66:in `load_script'
kernel/delta/code_loader.rb:200:in `load_script'
kernel/loader.rb:649:in `script'
kernel/loader.rb:831:in `main'
Tasks: TOP => test
(See full trace by running task with --trace)
You probably need to add bigdecimal or rubysl to your Gemfile. rubinius has gemified their stdlib, causing issues similar to this one.

Issues with mysql2 with and ruby

Trying to get the gem mysql2 installed on ubuntu and I have tried all of the suggestions but I cannot get it to run. Here is the error in my application.
./bla.rb:65:in `post_init': undefined method `query' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/em/timers.rb:51:in `fire'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `call'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run_machine'
from /var/lib/gems/1.8/gems/eventmachine-0.12.10/lib/eventmachine.rb:256:in `run'
from ./bla.rb:234:in `start_server'
from ./bin/minibardaemon:15
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:254:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:263:in `start_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/application.rb:295:in `start'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/controller.rb:73:in `run'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:197:in `run_proc'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `call'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons/cmdline.rb:109:in `catch_exceptions'
from /var/lib/gems/1.8/gems/daemons-1.1.8/lib/daemons.rb:196:in `run_proc'
I have installed all of the packages that are recommended and installed mysql2 via gem but still no luck.
libmysqlclient-dev
Is installed.
Im on Ubuntu.
# gem -v
1.3.7
# ruby -v
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
Installing the gems
# gem install mysql
Building native extensions. This could take a while...
Successfully installed mysql-2.8.1
1 gem installed
Installing ri documentation for mysql-2.8.1...
Installing RDoc documentation for mysql-2.8.1...
# gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysql2-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
def create_mysql2
begin
mysql2 = Mysql2::EM::Client.new(
:username => DBUSER,
:password => DBPASS,
:host => DBHOST,
:port => DBPORT,
:socket => DBSOCKET,
:database => DBNAME
)
return mysql2
rescue Mysql2::Error => exception
$stderr.puts "Mysql Error: #{ exception.message }"
EventMachine::stop_event_loop
end
end
...
begin
mysql2 = create_mysql2
rescue Exception => ex
p ex
end
# query the db every x seconds.
EventMachine::add_periodic_timer(QUERY_INTERVAL) do
defer1 = mysql2.query "SELECT * FROM table LIMIT #{QUERY_LIMIT}"
doesn't realy look like mysql2 gem issue, could you please show 65'th line of you bla.rb file? And probably some number of lines that surround it.
it actually looks like your mysql2 client gets uninitialized for some reason.
I would advice to check if something like this works:
require 'mysql2'
mysql_client = Mysql2::Client.new(:host => "localhost", :username => "root")
mysql_client.query('sql .. ')
if so, there's clearly an issue in your script

Simple use of EM::Synchrony#sync causes 'root fiber' FiberError -- my fault?

This program
require 'em-synchrony' ## v1.0.0
require 'em-hiredis' ## v0.1.0
module EventMachine
module Hiredis
class Client
def self.connect(host = 'localhost', port = 6379)
conn = new(host, port)
EM::Synchrony.sync conn.connect
conn
end
alias :old_method_missing :method_missing
def method_missing(sym, *args)
EM::Synchrony.sync old_method_missing(sym, *args)
end
end
end
end
EventMachine.synchrony do
redis = EM::Hiredis.connect
redis.set('foo', 'bar')
puts redis.get('foo')
EM.stop
end
dies like this
$ ruby /tmp/reddy.rb
/home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-synchrony-1.0.0/lib/em-synchrony.rb:58:in `yield': can't yield from root fiber (FiberError)
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-synchrony-1.0.0/lib/em-synchrony.rb:58:in `sync'
from /tmp/reddy.rb:16:in `method_missing'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/client.rb:119:in `select'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/client.rb:38:in `block in connect'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `call'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `block in emit'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `each'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/event_emitter.rb:8:in `emit'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-hiredis-0.1.0/lib/em-hiredis/connection.rb:15:in `connection_completed'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run_machine'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/eventmachine-1.0.0.beta.4/lib/eventmachine.rb:179:in `run'
from /home/blt/.rvm/gems/ruby-1.9.3-p0/gems/em-synchrony-1.0.0/lib/em-synchrony.rb:27:in `synchrony'
from /tmp/reddy.rb:22:in `<main>'
I find this deeply confusing. Why doesn't it work and am I at fault? If so, what can I do differently? Unless I've glossed over something, this is kosher, per the em-synchrony README.
I think your code can work if you find the correct version of em-hiredis it is trying to monkey patch, that is one problem with loose dependencies.
Here is a fully working code but based on the master branch of em-synchrony:
Gemfile:
source :rubygems
gem 'em-synchrony', :git => "git://github.com/igrigorik/em-synchrony.git"
gem 'em-hiredis', '~> 0.1.0'
test.rb:
require 'rubygems'
require 'bundler/setup'
require 'em-synchrony'
require 'em-synchrony/em-hiredis'
EventMachine.synchrony do
redis = EM::Hiredis.connect
redis.set('foo', 'bar')
puts redis.get('foo')
EM.stop
end
and then run it with:
$ bundle
$ ruby test.rb
Monkey patching is an inherently flawed way of patching gems unless you ensure the exact version of the gem you patched is used which is something em-synchrony should enforce or at least detect.

Resources