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

More informative error messages #100

Open
robjlucas opened this issue Apr 18, 2023 · 1 comment
Open

More informative error messages #100

robjlucas opened this issue Apr 18, 2023 · 1 comment

Comments

@robjlucas
Copy link

robjlucas commented Apr 18, 2023

There are lots of cases out there of users confused by cases of Capistrano apparently failing to find a version of Ruby that was installed with rbenv. In such cases we see output like this:

$ bundle exec cap staging deploy
00:00 rbenv:validate
      WARN  rbenv: 3.1.2 is not installed or not found in $HOME/.rbenv/versions/3.1.2 on 123.123.123.123

I was recently baffled by a case like this, because I knew for sure that this version of Ruby was installed in the specified location, and I hadn't changed anything.

It turned out that the underlying problem was simply that Capistrano was unable to log into the server, because the relevant user's password had expired and needed to be changed.

I would have been saved a lot of head scratching if the output from the rbenv:validate command had reflected this problem rather than seeming to imply that it had connected to the server in question but found Ruby absent at the specified path.

@mattbrictson
Copy link
Member

Great point! Thanks for bringing this up.

I think the underlying issue here is that rbenv:validate uses the test method, which simply returns true or false depending on whether the command succeeds, without printing any output. So when a command fails for unexpected reasons, like:

because the relevant user's password had expired and needed to be changed

then the user gets an unhelpful error message.

Source code of test method: https://github.com/capistrano/sshkit/blob/de8f33e4df6be1878b4143d61660c98e97a0d791/lib/sshkit/backends/abstract.rb#L59-L62

A simple solution might be to override the verbosity option used by test so that at least the underlying output from the command can be seen.

--- lib/capistrano/tasks/rbenv.rake
+++ lib/capistrano/tasks/rbenv.rake
@@ -7,7 +7,7 @@ namespace :rbenv do
       end
 
       # don't check the rbenv_ruby_dir if :rbenv_ruby is not set (it will always fail)
-      unless rbenv_ruby.nil? || (test "[ -d #{fetch(:rbenv_ruby_dir)} ]")
+      unless rbenv_ruby.nil? || (test("[ -d #{fetch(:rbenv_ruby_dir)} ]", verbosity: Logger::INFO))
         warn "rbenv: #{rbenv_ruby} is not installed or not found in #{fetch(:rbenv_ruby_dir)} on #{host}"
         exit 1
       end

That said, I don't actually use this gem, so I don't feel comfortable making this change without being able to test it.

I'll put a help wanted label on this issue for now.

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

No branches or pull requests

2 participants