telebugs 0.3.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4c0c10b30256a39ae190c425e5e5ff716472d3dd633de8f0fd7ac1fade8e03c9
4
- data.tar.gz: ff7cfd1b949fa1b4069174707a77e3ba1528bfc1a88e7b861356ec7df90a3771
3
+ metadata.gz: c16a99db8da62fc1f475458e2af48e686917a3591389e658fc98c717c2d8b72b
4
+ data.tar.gz: 862256bda596b7c3bb3e3b02dd1477137d225eedd3fad1fd3c0cc77d574a309b
5
5
  SHA512:
6
- metadata.gz: 183e8bb39eb85c81b0207c5fa10854038915b18e351df7b2c1ceebfb631092935f78a90d072ea0611865c482c0f01276b1e0f406ee593867c97c0ed2faca009e
7
- data.tar.gz: 4bab08e19990d6d79e263cadff184331c603109bf75afaa95f670b3be19d5df2efc8e81d4ec29c6be7ba3ae7fbaa3181c3a16f8aa7de5e7ea2c4cca4e3f4533c
6
+ metadata.gz: a0ae8dbc6726ee21a94e8f486d992a0c1850d754e7a2c1cf7ffc662976d4bcb68209d1fc67740fcb3769d331b48e3b4bee4704cecbf84b7a0324c727c81917a9
7
+ data.tar.gz: 86768ba7aabaf96cad7daeae5d2b3d00a83159e70fc576e539058ca8cca16d91e7e20353455d17a92717ee25b041932c54ae8523c6ae42af8f7e0d35d7f1fb46
@@ -5,10 +5,10 @@ module Telebugs
5
5
  ERROR_API_URL = "https://api.telebugs.com/2024-03-28/errors"
6
6
 
7
7
  attr_accessor :api_key,
8
- :root_directory,
9
8
  :middleware
10
9
 
11
- attr_reader :api_url
10
+ attr_reader :api_url,
11
+ :root_directory
12
12
 
13
13
  class << self
14
14
  attr_writer :instance
@@ -26,6 +26,15 @@ module Telebugs
26
26
  @api_url = URI(url)
27
27
  end
28
28
 
29
+ def root_directory=(directory)
30
+ @root_directory = File.realpath(directory)
31
+
32
+ if @middleware
33
+ @middleware.delete(Middleware::RootDirectoryFilter)
34
+ @middleware.use Middleware::RootDirectoryFilter.new(@root_directory)
35
+ end
36
+ end
37
+
29
38
  def reset
30
39
  self.api_key = nil
31
40
  self.api_url = ERROR_API_URL
@@ -35,6 +44,8 @@ module Telebugs
35
44
  )
36
45
 
37
46
  @middleware = MiddlewareStack.new
47
+ @middleware.use Middleware::GemRootFilter.new
48
+ @middleware.use Middleware::RootDirectoryFilter.new(root_directory)
38
49
  end
39
50
  end
40
51
  end
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telebugs
4
+ class Middleware
5
+ # GemRootFilter is a middleware that filters out the root path of the gems.
6
+ # It replaces the root path with the gem name and version.
7
+ class GemRootFilter < Telebugs::Middleware
8
+ def initialize
9
+ @gem_paths = Gem.path.map { |path| /\A#{Regexp.escape(path)}\/gems\// }
10
+ end
11
+
12
+ def call(report)
13
+ report.data[:errors].each do |error|
14
+ process_backtrace(error[:backtrace])
15
+ end
16
+ end
17
+
18
+ def weight
19
+ -999
20
+ end
21
+
22
+ private
23
+
24
+ def process_backtrace(backtrace)
25
+ backtrace.each do |frame|
26
+ next unless (file = frame[:file])
27
+
28
+ process_frame(frame, file)
29
+ end
30
+ end
31
+
32
+ def process_frame(frame, file)
33
+ @gem_paths.each do |gem_path_regex|
34
+ next unless file&.match?(gem_path_regex)
35
+
36
+ frame[:file] = format_file(file.sub(gem_path_regex, ""))
37
+ break
38
+ end
39
+ end
40
+
41
+ def format_file(file)
42
+ parts = file.split("/")
43
+
44
+ gem_info = parts[0].split("-")
45
+ gem_name = gem_info[0]
46
+ gem_version = gem_info[1]
47
+
48
+ file_path = parts[1..].join("/")
49
+
50
+ "#{gem_name} (#{gem_version}) #{file_path}"
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Telebugs
4
+ class Middleware
5
+ # Filters out the root directory from the backtrace paths.
6
+ class RootDirectoryFilter < Telebugs::Middleware
7
+ def initialize(root_directory)
8
+ @root_directory = root_directory
9
+ end
10
+
11
+ def call(report)
12
+ report.data[:errors].each do |error|
13
+ error[:backtrace].each do |frame|
14
+ next unless (file = frame[:file])
15
+ next unless file.start_with?(@root_directory)
16
+
17
+ file.sub!(/#{@root_directory}\/?/, "")
18
+ end
19
+ end
20
+ end
21
+
22
+ def weight
23
+ -999
24
+ end
25
+ end
26
+ end
27
+ end
@@ -21,6 +21,10 @@ module Telebugs
21
21
  @middlewares = (@middlewares << new_middleware).sort_by(&:weight).reverse
22
22
  end
23
23
 
24
+ def delete(middleware_class)
25
+ @middlewares.delete_if { |middleware| middleware.instance_of?(middleware_class) }
26
+ end
27
+
24
28
  def call(report)
25
29
  @middlewares.each do |middleware|
26
30
  middleware.call(report)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Telebugs
4
- VERSION = "0.3.0"
4
+ VERSION = "0.5.0"
5
5
  end
data/lib/telebugs.rb CHANGED
@@ -19,6 +19,9 @@ require_relative "telebugs/middleware"
19
19
  require_relative "telebugs/middleware_stack"
20
20
  require_relative "telebugs/truncator"
21
21
 
22
+ require_relative "telebugs/middleware/gem_root_filter"
23
+ require_relative "telebugs/middleware/root_directory_filter"
24
+
22
25
  module Telebugs
23
26
  # The general error that this library uses when it wants to raise.
24
27
  Error = Class.new(StandardError)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: telebugs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyrylo Silin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-06-15 00:00:00.000000000 Z
11
+ date: 2024-06-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -58,6 +58,8 @@ files:
58
58
  - lib/telebugs/error_message.rb
59
59
  - lib/telebugs/file_cache.rb
60
60
  - lib/telebugs/middleware.rb
61
+ - lib/telebugs/middleware/gem_root_filter.rb
62
+ - lib/telebugs/middleware/root_directory_filter.rb
61
63
  - lib/telebugs/middleware_stack.rb
62
64
  - lib/telebugs/promise.rb
63
65
  - lib/telebugs/report.rb