Rails : Could not find jwt-1.5.3 in any of the sources

I have been using Capistrano for a long time for this project. This time when I tried to deploy my latest changes I stumbled upon this issue. So I documented this.

 

(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as user@mysite.com: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........
Regenerating ruby-2.2.1 wrappers........
/usr/local/rvm/gems/ruby-2.2.1/gems/bundler-1.11.2/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:356: warning: Insecure world writable dir /usr/local/rvm/gems/ruby-2.2.1/bin in PATH, mode 042777

SSHKit::Command::Failed: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........
Regenerating ruby-2.2.1 wrappers........
/usr/local/rvm/gems/ruby-2.2.1/gems/bundler-1.11.2/lib/bundler/vendor/thor/lib/thor/shell/basic.rb:356: warning: Insecure world writable dir /usr/local/rvm/gems/ruby-2.2.1/bin in PATH, mode 042777

Tasks: TOP => deploy:updated => bundler:install
(See full trace by running task with --trace)
The deploy has failed with an error: Exception while executing as deployer@45.79.200.151: bundle exit status: 7
bundle stdout: Could not find jwt-1.5.3 in any of the sources
bundle stderr: Regenerating ruby-2.2.1 wrappers........

 

The reason is:

https://rubygems.org/gems/jwt/versions/1.5.3

jwt 1.5.3 is yanked because of some reasons. So 1.5.3 version isn’t in repository..!

How to solve

Delete your Gemfile.lock and

$ bundle install

update your remote repo and deploy again

Sources:

http://stackoverflow.com/a/36219627/3437900

Making Ruby Gems executable from terminal : Standalone

I presume you have developed a ruby gem. Its working fine when required to another ruby application. Now you want to make it standalone and running from terminal.

Wondering how to do that?

Its preety simple and straight forward way. All stuffs are done by the bundler itself. You just need to configure it properly.

It was different in older bundler version.. but now it works like this

In you_gem.gemspec

# it tells bundler that all executable files are inside `exe` dir
#   see http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }

 

So you need to keep all of your executables inside `exe` folder and sample exe file looks like. the file name is just ‘hulaki‘ with no extension.

#!/usr/bin/env ruby
# encoding: UTF-8
# exe/hulaki

# $: is just a shortcut for $LOAD_PATH. __FILE__ is the relative 
#   path to the script. This adds the current script directory 
#   to the load path
this_file = Pathname.new(__FILE__).realpath
$:.unshift File.expand_path("../../lib", this_file)
require 'hulaki'

Sources:

http://bundler.io/blog/2015/03/20/moving-bins-to-exe.html

http://stackoverflow.com/questions/9238367/ruby-unshift-file-dirname-file

Check the return value of “save”, otherwise use “save!”

Before

If you use “save” on an invalid record, it will not be saved:

post = Posts.new do |p|
  p.title = "example"
  p.body = "An example"
end
post.save

This code may work at the moment, but it is fragile. If a later refactoring introduces a new required column to Posts, then the save call will silently start failing.

Refactor

If you you think the record can never be invalid, or don’t want to check the return value, use “save!

post = Posts.new do |p|
  p.title = "example"
  p.body = "An example"
end
post.save!

Now you will get an error if the post cannot be saved, which will alert you to the problem.

And for production you can use https://github.com/fnando/notifier to send `UnCaught` exception notifications

Ruby : RubyGems : What does RubyGem do?

  • RubyGems is a package manager for the Ruby programming language that provides a standard format for distributing Ruby programs and libraries (in a self-contained format called a “gem“), a tool designed to easily manage the installation of gems, and a server for distributing them.

REQUIRING CODE

RubyGems modifies your Ruby load path, which controls how your Ruby code is found by the require statement. When you require a gem, really you’re just placing that gem’s lib directory onto your $LOAD_PATH.

$ irb -rpp
>> require 'ap'
# 'ap' is a gem or lib you just installed in the system
=> true
>> pp $LOAD_PATH.first
".../gems/awesome_print-1.0.2/lib"

Note: For Ruby 1.8 you must require ‘rubygems’ before requiring any gems.

sources:

http://guides.rubygems.org/rubygems-basics/#requiring-code

en.wikipedia.org/wiki/RubyGems