-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
filter_chain: factor out filters to separate classes
- Loading branch information
Showing
5 changed files
with
75 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Airbrake | ||
module Filters | ||
## | ||
# Replaces paths to gems with a placeholder. | ||
class GemRootFilter | ||
## | ||
# @return [String] | ||
GEM_ROOT_LABEL = '[GEM_ROOT]'.freeze | ||
|
||
def call(notice) | ||
return unless defined?(Gem) | ||
|
||
notice[:errors].each do |error| | ||
Gem.path.each do |gem_path| | ||
error[:backtrace].each do |frame| | ||
# If the frame is unparseable, then 'file' is nil, thus nothing to | ||
# filter (all frame's data is in 'function' instead). | ||
next unless (file = frame[:file]) | ||
file.sub!(/\A#{gem_path}/, GEM_ROOT_LABEL) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Airbrake | ||
module Filters | ||
## | ||
# Replaces root directory with a label. | ||
class RootDirectoryFilter | ||
## | ||
# @return [String] | ||
PROJECT_ROOT_LABEL = '[PROJECT_ROOT]'.freeze | ||
|
||
def initialize(root_directory) | ||
@root_directory = root_directory | ||
end | ||
|
||
def call(notice) | ||
notice[:errors].each do |error| | ||
error[:backtrace].each do |frame| | ||
next unless (file = frame[:file]) | ||
file.sub!(/\A#{@root_directory}/, PROJECT_ROOT_LABEL) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module Airbrake | ||
module Filters | ||
## | ||
# Skip over SystemExit exceptions, because they're just noise. | ||
class SystemExitFilter | ||
## | ||
# @return [String] | ||
SYSTEM_EXIT_TYPE = 'SystemExit'.freeze | ||
|
||
def call(notice) | ||
return if notice[:errors].none? { |error| error[:type] == SYSTEM_EXIT_TYPE } | ||
notice.ignore! | ||
end | ||
end | ||
end | ||
end |