Skip to content

Commit f590f40

Browse files
committed
Lint/InheritException
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.
1 parent 5570da5 commit f590f40

File tree

6 files changed

+5
-16
lines changed

6 files changed

+5
-16
lines changed

.rubocop_todo.yml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -585,17 +585,6 @@ Layout/TrailingWhitespace:
585585
Lint/ConstantDefinitionInBlock:
586586
Enabled: false
587587

588-
# This cop supports safe auto-correction (--auto-correct).
589-
# Configuration parameters: EnforcedStyle.
590-
# SupportedStyles: standard_error, runtime_error
591-
Lint/InheritException:
592-
Exclude:
593-
- 'lib/puppet/agent.rb'
594-
- 'lib/puppet/network/http/error.rb'
595-
- 'lib/puppet/pops/evaluator/closure.rb'
596-
- 'lib/puppet/util/logging.rb'
597-
- 'lib/puppet/util/retry_action.rb'
598-
599588
Lint/MissingSuper:
600589
Enabled: false
601590

lib/puppet/agent.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Puppet::Agent
1818
include Puppet::Util::Splayer
1919

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

2424
attr_reader :client_class, :client, :should_fork

lib/puppet/network/http/error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
module Puppet::Network::HTTP::Error
55
Issues = Puppet::Network::HTTP::Issues
66

7-
class HTTPError < Exception
7+
class HTTPError < Exception # rubocop:disable Lint/InheritException
88
attr_reader :status, :issue_kind
99

1010
def initialize(message, status, issue_kind)

lib/puppet/pops/evaluator/closure.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22
module Puppet::Pops
33
module Evaluator
4-
class Jumper < Exception
4+
class Jumper < Exception # rubocop:disable Lint/InheritException
55
attr_reader :value
66
attr_reader :file
77
attr_reader :line

lib/puppet/util/logging.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def log_and_raise(exception, message)
125125
raise exception, message + "\n" + exception.to_s, exception.backtrace
126126
end
127127

128-
class DeprecationWarning < Exception; end
128+
class DeprecationWarning < Exception; end # rubocop:disable Lint/InheritException
129129

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

lib/puppet/util/retry_action.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22
module Puppet::Util::RetryAction
3-
class RetryException < Exception; end
3+
class RetryException < Exception; end # rubocop:disable Lint/InheritException
44
class RetryException::NoBlockGiven < RetryException; end
55
class RetryException::NoRetriesGiven < RetryException;end
66
class RetryException::RetriesExceeded < RetryException; end

0 commit comments

Comments
 (0)