Module: Ask::SolidErrors

Defined in:
lib/ask/solid_errors/client.rb,
lib/ask/solid_errors/context.rb,
lib/ask/solid_errors/version.rb,
lib/ask/solid_errors/error_guide.rb

Defined Under Namespace

Modules: Errors Classes: ClientProxy

Constant Summary collapse

DESCRIPTION =

Human-readable description of the SolidErrors service context.

"SolidErrors — error tracking stored in your Rails database"
GEM_NAME =

Gem name for the SolidErrors tracker.

"solid_errors"
QUICK_START =

Quick-start Ruby code snippet for agents to copy-paste.

<<~RUBY
  errors = Ask::SolidErrors.recent(limit: 10)
  errors.map { |e| { id: e.id, class: e.exception_class, message: e.message.truncate(200) } }

  # Or get full details:
  error = Ask::SolidErrors.find(id)
  error.backtrace
  error.context

  # Or work with occurrences:
  error = Ask::SolidErrors.find(id)
  error.occurrences.each do |occ|
    puts occ.parsed_backtrace
  end
RUBY
VERSION =
"0.1.0"

Class Method Summary collapse

Class Method Details

.by_class(klass) ⇒ ActiveRecord::Relation<SolidErrors::Error>

Convenience — filter errors by exception class name.

Parameters:

  • klass (String)

    exception class name (e.g. “ActiveRecord::RecordNotFound”)

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


59
60
61
# File 'lib/ask/solid_errors/client.rb', line 59

def self.by_class(klass)
  client.where(exception_class: klass)
end

.by_severity(severity) ⇒ ActiveRecord::Relation<SolidErrors::Error>

Convenience — filter errors by severity level.

Parameters:

  • severity (String)

    severity level (“error”, “warning”, “info”)

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


67
68
69
# File 'lib/ask/solid_errors/client.rb', line 67

def self.by_severity(severity)
  client.where(severity: severity)
end

.clientClientProxy

Returns a client proxy for querying SolidErrors.

No authentication is needed — SolidErrors runs in the same database as the Rails app. The proxy delegates to SolidErrors::Error and SolidErrors::Occurrence models, returning ActiveRecord::Relation objects that can be further chained by the agent.

Examples:

Ask::SolidErrors.recent(limit: 5)
Ask::SolidErrors.unresolved
Ask::SolidErrors.by_class("ActiveRecord::RecordNotFound")

Returns:

  • (ClientProxy)

    a proxy wrapping SolidErrors::Error

Raises:

  • (LoadError)

    if the solid_errors gem is not installed



19
20
21
22
# File 'lib/ask/solid_errors/client.rb', line 19

def self.client
  ensure_solid_errors_loaded!
  ClientProxy.new
end

.ensure_solid_errors_loaded!Object

Raise LoadError with a clear message when the solid_errors gem is not available.

Raises:

  • (::LoadError)


137
138
139
140
141
142
# File 'lib/ask/solid_errors/client.rb', line 137

def self.ensure_solid_errors_loaded!
  return if defined?(::SolidErrors)

  raise ::LoadError, "The `solid_errors` gem is not installed. " \
                     "Add `gem 'solid_errors'` to your Gemfile and run `bundle install`."
end

.find(id) ⇒ SolidErrors::Error

Convenience — find a single error by its primary key.

Parameters:

  • id (Integer, String)

    error record ID

Returns:

  • (SolidErrors::Error)

Raises:

  • (ActiveRecord::RecordNotFound)

    if the record does not exist



37
38
39
# File 'lib/ask/solid_errors/client.rb', line 37

def self.find(id)
  client.find(id)
end

.occurrence_count(error) ⇒ Integer

Convenience — return the occurrence count for an error.

Parameters:

  • error (SolidErrors::Error, Integer)

    error record or its ID

Returns:

  • (Integer)


83
84
85
# File 'lib/ask/solid_errors/client.rb', line 83

def self.occurrence_count(error)
  client.occurrence_count(error)
end

.recent(limit: 10) ⇒ ActiveRecord::Relation<SolidErrors::Error>

Convenience — return the most recently recorded errors.

Parameters:

  • limit (Integer) (defaults to: 10)

    number of errors to return (default: 10)

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


28
29
30
# File 'lib/ask/solid_errors/client.rb', line 28

def self.recent(limit: 10)
  client.recent(limit: limit)
end

.resolvedActiveRecord::Relation<SolidErrors::Error>

Convenience — return all resolved errors.

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


51
52
53
# File 'lib/ask/solid_errors/client.rb', line 51

def self.resolved
  client.resolved
end

.search(query) ⇒ ActiveRecord::Relation<SolidErrors::Error>

Convenience — search errors whose message contains the given text.

Parameters:

  • query (String)

    search text

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


75
76
77
# File 'lib/ask/solid_errors/client.rb', line 75

def self.search(query)
  client.where("message LIKE ?", "%#{client.sanitize_sql_like(query)}%")
end

.unresolvedActiveRecord::Relation<SolidErrors::Error>

Convenience — return all unresolved errors.

Returns:

  • (ActiveRecord::Relation<SolidErrors::Error>)


44
45
46
# File 'lib/ask/solid_errors/client.rb', line 44

def self.unresolved
  client.unresolved
end