Skip to content

Commit

Permalink
Lint/InheritException
Browse files Browse the repository at this point in the history
Ruby's `rescue => e` only rescues StandardException so it's preferrable to
always create exceptions that inherit from StandardException, not Exception.
However, there are times where we intentially do want to inherit from Exception.

In the evaluator, break, next, etc relies on inheriting from Exception for
control flow.

In a few other cases, changing the hierarchy would break anyone using puppet
as a library, so disable them on a case-by-case basis.
  • Loading branch information
joshcooper committed Dec 1, 2023
1 parent bb8b303 commit d676d30
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 15 deletions.
11 changes: 0 additions & 11 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -585,17 +585,6 @@ Layout/TrailingWhitespace:
Lint/ConstantDefinitionInBlock:
Enabled: false

# This cop supports safe auto-correction (--auto-correct).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: standard_error, runtime_error
Lint/InheritException:
Exclude:
- 'lib/puppet/agent.rb'
- 'lib/puppet/network/http/error.rb'
- 'lib/puppet/pops/evaluator/closure.rb'
- 'lib/puppet/util/logging.rb'
- 'lib/puppet/util/retry_action.rb'

Lint/MissingSuper:
Enabled: false

Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Puppet::Agent
include Puppet::Util::Splayer

# Special exception class used to signal an agent run has timed out.
class RunTimeoutError < Exception
class RunTimeoutError < Exception # rubocop:disable Lint/InheritException
end

attr_reader :client_class, :client, :should_fork
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/network/http/error.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
module Puppet::Network::HTTP::Error
Issues = Puppet::Network::HTTP::Issues

class HTTPError < Exception
class HTTPError < Exception # rubocop:disable Lint/InheritException
attr_reader :status, :issue_kind

def initialize(message, status, issue_kind)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/pops/evaluator/closure.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true
module Puppet::Pops
module Evaluator
class Jumper < Exception
class Jumper < Exception # rubocop:disable Lint/InheritException
attr_reader :value
attr_reader :file
attr_reader :line
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet/util/logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def log_and_raise(exception, message)
raise exception, message + "\n" + exception.to_s, exception.backtrace
end

class DeprecationWarning < Exception; end
class DeprecationWarning < Exception; end # rubocop:disable Lint/InheritException

# Logs a warning indicating that the Ruby code path is deprecated. Note that
# this method keeps track of the offending lines of code that triggered the
Expand Down

0 comments on commit d676d30

Please sign in to comment.