solid_errors 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2dca714cf4ffe599a29937d67dee7c3f9b3ee0afc80b6ccde95398fde79ade60
4
- data.tar.gz: 01e5584fa510677bc359caab0a1860a90c253021c5676690fbaba40d2674e72a
3
+ metadata.gz: 3afcbab51fec686b6c7ea6fc4b6f3238cefbd5b53436fb9693f8905b164dcbaf
4
+ data.tar.gz: af9f2125d09f34289170be9b0fdb896dbd381d841668d99b9a5c4cb02e05b89b
5
5
  SHA512:
6
- metadata.gz: 4ed600ae17b66b31f6cf3311f6cc041d00caea054d3b50a9a14ea9801997cdcd4bb79377ec3568efc57ef6157c530249a242a431fb106f1d04f79e8816148473
7
- data.tar.gz: 9f1317997604b7a23756f52d6c27b57ba9e8481f21e56cb2f93a1a33f1ca9c4901086322b154bfc5e54d3da4820a56c13baaa51da2644bb01c01bc362a16cf60
6
+ metadata.gz: 5b15312915ddea9a4313a69ad86675f657b3a046205270876129008ba9aefbe8db956424010c124f81c9c71d35530571838f5286d5a324fb29faa04be1503017
7
+ data.tar.gz: 78afed7dd8d60b9bb435c83d0124216eaf3ef3eab2e61e58624180beac52e31a432f8a5232b829f12d712b6b40a9b1ded86b92936c6fe97ca0b831dfd1f41e8b
@@ -0,0 +1,34 @@
1
+ module SolidErrors
2
+ class ErrorsController < ApplicationController
3
+ before_action :set_error, only: %i[ show update ]
4
+
5
+ # GET /errors
6
+ def index
7
+ @errors = Error.unresolved
8
+ .joins(:occurrences)
9
+ .select('errors.*, MAX(occurrences.created_at) AS recent_occurrence')
10
+ .group('errors.id')
11
+ .order('recent_occurrence DESC')
12
+ end
13
+
14
+ # GET /errors/1
15
+ def show
16
+ end
17
+
18
+ # PATCH/PUT /errors/1
19
+ def update
20
+ @error.update!(error_params)
21
+ redirect_to errors_path, notice: "Error marked as resolved."
22
+ end
23
+
24
+ private
25
+ # Only allow a list of trusted parameters through.
26
+ def error_params
27
+ params.require(:error).permit(:resolved_at)
28
+ end
29
+
30
+ def set_error
31
+ @error = Error.find(params[:id])
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,22 @@
1
+ module SolidErrors
2
+ class Error < Record
3
+ SEVERITY_TO_EMOJI = {
4
+ error: "🔥",
5
+ warning: "⚠️",
6
+ info: "ℹ️"
7
+ }
8
+
9
+ has_many :occurrences, class_name: "SolidErrors::Occurrence", dependent: :destroy
10
+
11
+ validates :exception_class, presence: true
12
+ validates :message, presence: true
13
+ validates :severity, presence: true
14
+
15
+ scope :resolved, -> { where.not(resolved_at: nil) }
16
+ scope :unresolved, -> { where(resolved_at: nil) }
17
+
18
+ def emoji
19
+ SEVERITY_TO_EMOJI[severity.to_sym]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ module SolidErrors
2
+ class Occurrence < Record
3
+ belongs_to :error
4
+
5
+ # The parsed exception backtrace. Lines in this backtrace that are from installed gems
6
+ # have the base path for gem installs replaced by "[GEM_ROOT]", while those in the project
7
+ # have "[PROJECT_ROOT]".
8
+ # @return [Array<{:number, :file, :method => String}>]
9
+ def parsed_backtrace
10
+ return @parsed_backtrace if defined? @parsed_backtrace
11
+
12
+ @parsed_backtrace = parse_backtrace(backtrace.split("\n"))
13
+ end
14
+
15
+ private
16
+
17
+ def parse_backtrace(backtrace)
18
+ Backtrace.parse(backtrace)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SolidErrors
4
+ class Record < ActiveRecord::Base
5
+ self.abstract_class = true
6
+
7
+ connects_to **SolidErrors.connects_to if SolidErrors.connects_to
8
+ end
9
+ end
10
+
11
+ ActiveSupport.run_load_hooks :solid_errors_record, SolidErrors::Record