Skip to content

Commit

Permalink
[engine/cli.rb] Handle nil name_padding
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
NickLaMuro authored and ddollar committed Apr 12, 2024
1 parent 14aba8d commit fb80608
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/foreman/engine/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit fb80608

Please sign in to comment.