Skip to content

Instantly share code, notes, and snippets.

@alloy-d
Created February 11, 2014 20:29
Show Gist options
  • Save alloy-d/8943443 to your computer and use it in GitHub Desktop.
Save alloy-d/8943443 to your computer and use it in GitHub Desktop.
Censoring wordy exceptions.
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
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