Class: RailsErrorDashboard::Commands::FindOrIncrementError

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_error_dashboard/commands/find_or_increment_error.rb

Overview

Command: Find an existing error by hash or create a new one Uses pessimistic locking to prevent race conditions in multi-app scenarios.

Search order:

  1. Unresolved errors with same hash within 24 hours → increment occurrence count
  2. Resolved/wont_fix errors with same hash (any age) → reopen and increment
  3. No match → create new error record

Environment is a MATCH dimension, not part of the hash: the same error in staging and production is two rows with independent status. A row with a NULL environment predates the column; it matches as a wildcard and is stamped by the first occurrence that claims it, so history migrates itself without a backfill. An exact match always wins over a NULL one.

Constant Summary collapse

REFRESHED_CONTEXT =

Context that describes THIS occurrence rather than the error as a group. It is refreshed on every recurrence so the row always shows the latest moment of failure, not the first one in the 24 h window. Keys absent from @attributes (feature disabled, column not migrated, or a storm :lite capture that shed context) leave the stored payload alone — a shed capture must never blank out a good snapshot.

%i[
  breadcrumbs system_health local_variables instance_variables
  http_method hostname content_type request_duration_ms
].freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(error_hash, attributes = {}) ⇒ FindOrIncrementError

Returns a new instance of FindOrIncrementError.



34
35
36
37
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 34

def initialize(error_hash, attributes = {})
  @error_hash = error_hash
  @attributes = attributes
end

Class Method Details

.call(error_hash, attributes = {}) ⇒ Object



30
31
32
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 30

def self.call(error_hash, attributes = {})
  new(error_hash, attributes).call
end

Instance Method Details

#callObject



39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/rails_error_dashboard/commands/find_or_increment_error.rb', line 39

def call
  # Priority 1: Find unresolved match (existing behavior)
  existing = find_unresolved
  return increment_existing(existing) if existing

  # Priority 2: Find resolved/wont_fix match → reopen
  resolved = find_resolved
  return reopen_existing(resolved) if resolved

  # Priority 3: Create new record
  create_new_or_retry
end