Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: undefined method `colorize' for :deploy:Symbol #214

Closed
EverybodyKurts opened this issue Jan 15, 2015 · 17 comments

Comments

@EverybodyKurts
Copy link

First, thank you for all the hard work you guys have done on this project and capistrano. Capistrano is a critical a tool in the development, maintenance, and deployment of my rails apps. I don't know if you guys hear that enough, but you should know that almost every rails dev I talk to uses capistrano to deploy. So thank you again.

Now, on to it:

Gem versions:

capistrano 3.3.5
sshkit 1.6.1
colorize 0.7.5

Whenever I attempt to attempt to deploy via the cap deploy task, I get the following error:

SSHKit::Runner::ExecuteError: Exception while executing as [email protected]: undefined method `colorize' for :deploy:Symbol

After running a stack trace, the error pointed to /lib/sshkit/color.rb:7.

module Color
  String.colors.each do |color|
    instance_eval <<-RUBY, __FILE__, __LINE__
      def #{color}(string = '')
        string = yield if block_given?
        colorize? ? string.colorize(:color => :#{color}) : string  # LINE 7
      end
    RUBY
  end

  # omitted
end

The quick fix for me was simply calling to_s on string

colorize? ? string.to_s.colorize(:color => :#{color}) : string

I don't know if this is the right solution (probably not), but it solved my problem. If you like, I can submit a pull request.

@leehambley
Copy link
Member

Hey @KurtRMueller the problem is colorize gem, which recently released a 7.5.0 version, if you check what you have, and try using an old(er) one, it should be fine, we've a couple of open PRs for this already, but there's some more cleanups I wanted to tackle other than just monkey patching the one liner colour issue.

It turns out (in fairness to the Colorize author) that we were using a kind-of internal API of theirs, which finally went away, our bad.

We have a general policy of not strictly policing our version dependencies, there'd be hardly anything more annoying than Capistrano (via SSHKit, for example) forcing you to use … for deployment, and only for deployment some arcane combination of Gems which you might very legitimately need at other versions for your actual application, so we need to find a solution that works for a broad range of colorize versions.

@joshuapaling
Copy link

For anyone still having the same issue, the really short story is this:

  # in your Gemfile
  gem 'capistrano-rails'
  gem 'colorize', '0.7.4'

and then run bundle update colorize

IE, just lock colorize at version 0.7.4 and the issue should go away.

@leehambley
Copy link
Member

As written before, we explicitly choose not to force a specific coloroze
version, as a library that people put in their Gemfile, it would be
annoying for us to force an incidental version dependency on your app.

Sent from my Nexus 5.
On 4 Mar 2015 01:11, "Joshua Paling" [email protected] wrote:

For anyone still having the same issue, the really short story is this:

in your Gemfile

gem 'capistrano-rails'
gem 'colorize', '0.7.4'

and then run bundle update colorize

IE, just lock colorize at version 0.7.4 and the issue should go away.


Reply to this email directly or view it on GitHub
#214 (comment).

@joshuapaling
Copy link

I know. My comment was advice to users of capistrano, not to you as the maintainer. Thanks for all the hard work you do on capistrano.

@leehambley
Copy link
Member

:-)

Sent from my Nexus 5.
On 4 Mar 2015 23:16, "Joshua Paling" [email protected] wrote:

I know. My comment was advice to users of capistrano, not to you as the
maintainer. Thanks for all the hard work you do on capistrano.


Reply to this email directly or view it on GitHub
#214 (comment).

@marvwhere
Copy link

any updates on this one? just run into it, and only solution for me was to patch the gem as said above tried around with locking different versions, but did not helped.

@leehambley
Copy link
Member

We don't explicitly lock versions of Colorize (otherwise your deployment tool would be dictating your runtime dependencies)… you don't have to patch anything, make sure (even via distant deps) that you don't rely on colorize. I guess eventually we'll have to remove it completely as a dependency.

@brewster1134
Copy link

i had to fix this by rolling back to sshkit 1.4. 1.5 & 1.6 had the same issue

gem 'sshkit', '~> 1.4.0'

@robd
Copy link
Contributor

robd commented May 8, 2015

@brewster1134 If possible could you send through the full stack trace, plus the version of capistrano you are using. Thanks!

@brewster1134
Copy link

@robd here you go...

➜  ruby -v
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13]
➜  cap -v
Capistrano Version: 3.4.0 (Rake Version: 10.4.2)
➜  bundle -v
Bundler version 1.7.11
➜  be cap production deploy -t
** Invoke production (first_time)
** Execute production
** Invoke load:defaults (first_time)
** Execute load:defaults
** Invoke bundler:map_bins (first_time)
** Execute bundler:map_bins
** Invoke deploy:set_rails_env (first_time)
** Execute deploy:set_rails_env
** Invoke deploy (first_time)
** Execute deploy
** Invoke deploy:starting (first_time)
** Execute deploy:starting
** Invoke deploy:check (first_time)
** Execute deploy:check
** Invoke git:check (first_time)
** Invoke git:wrapper (first_time)
** Execute git:wrapper
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as deploy@[IP ADDRESS]: undefined method `colorize' for :deploy:Symbol
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:16:in `rescue in block (2 levels) in execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
NoMethodError: undefined method `colorize' for :deploy:Symbol
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/color.rb:7:in `blue'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/formatters/pretty.rb:23:in `write_command'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/formatters/pretty.rb:10:in `write'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:134:in `block in _execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/capistrano-3.4.0/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:13:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
The deploy has failed with an error: Exception while executing as deploy@[IP ADDRESS]: undefined method `colorize' for :deploy:Symbol
** Invoke deploy:failed (first_time)
** Execute deploy:failed

@robd
Copy link
Contributor

robd commented May 8, 2015

@brewster1134 Thank you very much. As @mattbrictson mentioned, I hope to fix this soon, but I want to get to the bottom of why it's happening and add a test if necessary. Unfortunately, it appears that netssh is swallowing the original exception stack. Would you be able to delete the begin / rescue block in /usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb
and run the task again.

ie here:

threads << Thread.new(host) do |h|
  begin
    backend(h, &block).run
  rescue Exception => e
    e2 = ExecuteError.new e
    raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
  end
end

Comment out / delete the begin rescue:

threads << Thread.new(host) do |h|
  #begin
    backend(h, &block).run
  #rescue Exception => e
  #  e2 = ExecuteError.new e
  #  raise e2, "Exception while executing #{host.user ? "as #{host.user}@" : "on host "}#{host}: #{e.message}"
  #end
end

@brewster1134
Copy link

😄

NoMethodError: undefined method `colorize' for :deploy:Symbol
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/color.rb:7:in `blue'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/formatters/pretty.rb:23:in `write_command'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/formatters/pretty.rb:10:in `write'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:134:in `block in _execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `tap'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:133:in `_execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:66:in `execute'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/capistrano-3.4.0/lib/capistrano/tasks/git.rake:17:in `block (3 levels) in <top (required)>'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `instance_exec'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/backends/netssh.rb:54:in `run'
/usr/local/var/rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/sshkit-1.7.1/lib/sshkit/runners/parallel.rb:12:in `block (2 levels) in execute'
Tasks: TOP => git:check => git:wrapper
The deploy has failed with an error: undefined method `colorize' for :deploy:Symbol
** Invoke deploy:failed (first_time)
** Execute deploy:failed

@robd
Copy link
Contributor

robd commented May 9, 2015

@brewster1134 I think this is because you are defining your user as the symbol :deploy on your server line:

server 'some_ip', port: some_port, user: :deploy, roles: %w{web app db}

If this is the case, could you try changing to a string:

server 'some_ip', port: some_port, user: 'deploy', roles: %w{web app db}

@brewster1134
Copy link

i think you're right! i never noticed that was a symbol. sorry for the false alarm. the deployment was successful with 1.7! thanks @robd

@brewster1134
Copy link

so looking at the OP's title for this issue, is it possible @KurtRMueller has the same issue? Strange if we both have a user named :deploy configured as a symbol. The deployment file i am using was handed to me from our devOps department, so perhaps :deploy is a common convention for capistrano? might want to throw a .to_s in the next sshkit patch version! thanks again!

@robd
Copy link
Contributor

robd commented May 9, 2015

No probs, as it happens some other work I'm doing over in #246 would have fixed this, but I think we should take a call on whether we want to allow users to be specified as symbols and either

a) add tests to ensure we support them
b) call to_s on the user in capistrano in the server method ✓
c) raise a helpful exception at the server method.

I will follow up with @leehambley but b seems like least work.

Anyway, thanks for following up on @KurtRMueller's original bug report and for helping to diagnose.

@leehambley
Copy link
Member

Colorize dependency was removed in db7de6d

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants