telebugs 0.4.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/telebugs/config.rb +13 -2
- data/lib/telebugs/middleware/gem_root_filter.rb +59 -0
- data/lib/telebugs/middleware/root_directory_filter.rb +27 -0
- data/lib/telebugs/version.rb +1 -1
- data/lib/telebugs.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b15d4f8c051d0aaf01a989d4222cb934bf3ed7a11b2ac63549824f9353fe98a
|
4
|
+
data.tar.gz: 8c2c8048c5799735d62a8dcc7ee8a28f7377775ab0d32670c0aef3814119a42b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: adc3cc6b7e25076da64c63479037f3c144536c02ca77bc8c6e0a4279d3ce2b37795f16bd010f37b71378c6c7f0ec40ad188aa179c7a050ea8af05731b53a0b07
|
7
|
+
data.tar.gz: ff81dc60d57b9a649b81e13ffd61a968c1edcdcd3892a3929b18cec379daafb7bd85dffd2e19a388fa04ff6504b4a82652d3c4c9e5bd46d236a4300dc5fddd4e
|
data/lib/telebugs/config.rb
CHANGED
@@ -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,59 @@
|
|
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
|
+
if gem_info.size < 2
|
46
|
+
gem_name = gem_info[0]
|
47
|
+
gem_version = gem_info[1]
|
48
|
+
else
|
49
|
+
gem_name = gem_info[0..-2].join("-")
|
50
|
+
gem_version = gem_info[-1]
|
51
|
+
end
|
52
|
+
|
53
|
+
file_path = parts[1..].join("/")
|
54
|
+
|
55
|
+
"#{gem_name} (#{gem_version}) #{file_path}"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
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
|
data/lib/telebugs/version.rb
CHANGED
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.
|
4
|
+
version: 0.6.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-
|
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
|