Skip to content

Commit

Permalink
Lint/InheritException
Browse files Browse the repository at this point in the history
It's preferrable to inherit from StandardException so that callers won't be
surprised if they do `rescue => e`.

In the evaluator, break, next, etc relies on this for control flow.

In a few other cases, the exception may be raised outside of puppet, so we can't
change the exception hierarchy.
  • Loading branch information
joshcooper committed Nov 21, 2023
1 parent 50693ee commit 98545ed
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 @@ -580,17 +580,6 @@ Layout/TrailingEmptyLines:
Layout/TrailingWhitespace:
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 98545ed

Please sign in to comment.