Created
February 11, 2014 20:29
-
-
Save alloy-d/8943443 to your computer and use it in GitHub Desktop.
Censoring wordy exceptions.
This file contains hidden or 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
require 'active_support/backtrace_cleaner' | |
module CensoredException | |
def self.extended(base) | |
orig_backtrace = base.method(:backtrace) | |
base.define_singleton_method(:backtrace) do | |
BACKTRACE_CLEANER.clean(orig_backtrace.call) | |
end | |
end | |
BACKTRACE_CLEANER = ActiveSupport::BacktraceCleaner.new | |
[ | |
%r{/gems/sinatra-\d}, | |
%r{/gems/rack(-protection)?-\d}, | |
%r{/gems/shotgun-\d}, | |
%r{/bin/shotgun}, | |
%r{/gems/thin-\d}, | |
%r{/gems/eventmachine-\d}, | |
].each do |pattern| | |
BACKTRACE_CLEANER.add_silencer {|line| line =~ pattern } | |
end | |
end |
This file contains hidden or 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
require 'sinatra' | |
require 'censored_exception' | |
class App < Sinatra::Base | |
def handle_exception!(boom) | |
boom.extend(CensoredException) | |
super(boom) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment