From fb80608edadbfe04a469ed445b91210b2c3e380e Mon Sep 17 00:00:00 2001 From: Nick LaMuro Date: Mon, 13 Jul 2020 17:19:16 -0500 Subject: [PATCH] [engine/cli.rb] Handle nil name_padding When (mistakenly) starting foreman with a empty Procfile, it ends up not being possible to exit this process via a TERM signal due to the following error: $ foreman start ERROR: Procfile does not exist. $ touch Procfile $ bin/foreman start ^Ccomparison of NilClass with 6 failed ./lib/foreman/engine/cli.rb:80:in `name_padding' ./lib/foreman/engine/cli.rb:85:in `pad_process_name' ./lib/foreman/engine/cli.rb:61:in `block in output' ./lib/foreman/engine/cli.rb:57:in `each' ./lib/foreman/engine/cli.rb:57:in `output' ./lib/foreman/engine.rb:335:in `block in output_with_mutex' ./lib/foreman/engine.rb:334:in `synchronize' ./lib/foreman/engine.rb:334:in `output_with_mutex' ./lib/foreman/engine.rb:340:in `system' ./lib/foreman/engine.rb:124:in `handle_interrupt' ./lib/foreman/engine.rb:104:in `handle_signal' ./lib/foreman/engine.rb:389:in `handle_signals' ./lib/foreman/engine.rb:412:in `block (2 levels) in watch_for_output' ./lib/foreman/engine.rb:409:in `loop' ./lib/foreman/engine.rb:409:in `block in watch_for_output' ^C^C^C^C^C^X^Z [1]+ Stopped bin/foreman start $ kill %1 $ jobs [1]+ Running bin/foreman start & $ jobs [1]+ Running bin/foreman start & $ kill -9 %1 [1]+ Killed: 9 bin/foreman start $ jobs By adding a `.to_i`, this simply allows the `Engine::Cli#name_padding` method to default to 6, allowing the rest of the shutdown process to finish executing and exit the process gracefully. --- lib/foreman/engine/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/foreman/engine/cli.rb b/lib/foreman/engine/cli.rb index 7ea71375..a6055332 100644 --- a/lib/foreman/engine/cli.rb +++ b/lib/foreman/engine/cli.rb @@ -77,7 +77,7 @@ def name_padding @name_padding ||= begin index_padding = @names.values.map { |n| formation[n] }.max.to_s.length + 1 name_padding = @names.values.map { |n| n.length + index_padding }.sort.last - [ 6, name_padding ].max + [ 6, name_padding.to_i ].max end end