class Dogcatcher::Notice

Constants

MAX_MESSAGE_SIZE

Attributes

action[RW]

Name of the action that caused the exception

exception[R]

The exception itself

metadata[RW]

Additional information about the exception

notifier[RW]

Name of the source that caught the exception

Public Class Methods

new(config, exception) click to toggle source

@param [Dogcatcher::Config] config @param [Exception] exception

# File lib/dogcatcher/notice.rb, line 19
def initialize(config, exception)
  @config = config
  @exception = exception
  @metadata = {}
end

Public Instance Methods

message() click to toggle source

Markdown-formatted message containing the backtrace and metadata.

@return [String]

# File lib/dogcatcher/notice.rb, line 28
def message
  backtrace = @config.backtrace_cleaner.clean(exception.backtrace)
  markdown = Markdown.new
  metadata.each { |key, value| markdown.bullet("#{key}: #{value}") }
  max_block_size = MAX_MESSAGE_SIZE - markdown.result.length - 10
  markdown.code_block(backtrace.join("\n"), 'text', max_block_size)
  markdown.result
end
tags() click to toggle source

Tags containing information about the event. If gem version tags are enabled then they will be included in the output.

@return [Array<String>]

# File lib/dogcatcher/notice.rb, line 41
def tags
  tagset = Dogcatcher::TagSet.new
  tagset << "notifier:#{notifier}"
  tagset << "action:#{action}"
  tagset << "exception_class:#{exception.class}"
  tagset << "program:#{@config.program}" if @config.program
  tagset << "ruby_version:#{RUBY_VERSION}"
  tagset.merge(gem_tags) if @config.gem_tags
  tagset.merge(@config.custom_tags)
  tagset.compile.to_a
end
title() click to toggle source

Title of the event/notice.

Includes the program name if a program name is configured.

@return [String]

# File lib/dogcatcher/notice.rb, line 58
def title
  program = "#{@config.program} - " if @config.program
  "#{program}#{exception.class}:#{exception.message}"
end

Private Instance Methods

gem_tags() click to toggle source

Searches for gem versions in the backtrace and derives tags from them.

@return [Array<String>]

# File lib/dogcatcher/notice.rb, line 68
def gem_tags
  exception.backtrace.map do |line|
    match = line.scan(%r{gems/[A-Za-z0-9\-_.]+/gems/([A-Za-z\-_]+)-([0-9.]+(\.[a-z]+(\.[0-9]+)?)?)/})
    match.empty? ? nil : match.flatten.compact.join(':')
  end.compact
end