Class: RuboCop::Cop::Chef::Correctness::ChefApplicationFatal
- Extended by:
- AutoCorrector
- Defined in:
- lib/rubocop/cop/chef/correctness/chef_application_fatal.rb
Overview
Use raise to force Chef Infra Client to fail instead of using Chef::Application.fatal, which masks the full stack trace of the failure and makes debugging difficult.
Chef::Application.fatal! optionally takes an exit code as a second argument. That form is
reported but not autocorrected, since raise has no way to express a specific exit code and
rewriting it would silently change how the run terminates.
Constant Summary collapse
- MSG =
'Use raise to force Chef Infra Client to fail instead of using Chef::Application.fatal'- RESTRICT_ON_SEND =
[:fatal!].freeze
Instance Method Summary collapse
Methods inherited from Base
Instance Method Details
#on_send(node) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rubocop/cop/chef/correctness/chef_application_fatal.rb', line 50 def on_send(node) application_fatal?(node) do |args| # Only the single message argument form maps cleanly onto raise. With an exit code (or # with no message at all) we still report, but leave the rewrite to a human. unless args.one? add_offense(node, severity: :refactor) next end add_offense(node, severity: :refactor) do |corrector| corrector.replace(node, "raise(#{args.first.source})") end end end |