redis-prescription 2.0.0 → 2.1.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 +4 -4
- data/lib/redis_prescription/errors.rb +68 -3
- data/lib/redis_prescription/version.rb +1 -1
- data/lib/redis_prescription.rb +2 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 617a2c55e0d763f97983c56f3e7c7fbea30b4c999736a0eb8eaa4f38dab3a684
|
4
|
+
data.tar.gz: 16ab341290e6ee88abe15d0c0ee5523b1aaa1ab7b0228e05c9650ff4b861cf52
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 654c70a9fda3e076291c0c5339cde768c430c4d960d434fedf9e3bf7e8aaab5d4ea280a1be3a8d554015b09fd8adec26a4f2349ee169cd43e3139ce2b9b6badd
|
7
|
+
data.tar.gz: ce8112a9aa153b41e05e4e327dbcb6b6bf62abd120a96dad1eacbf818e747899abd7615bf975484850cad540cd4669764e320ce7a07e07d447a371397fe33c55
|
@@ -10,17 +10,82 @@ class RedisPrescription
|
|
10
10
|
|
11
11
|
# Lua script eval/evalsha failure
|
12
12
|
class ScriptError < Error
|
13
|
-
#
|
13
|
+
# rubocop:disable Layout/LineLength
|
14
|
+
LUA_ERROR_MESSAGE = %r{
|
15
|
+
# * Error compiling script:
|
16
|
+
# ** Redis 6.0, 6.2, 7.0
|
17
|
+
# *** ERR Error compiling script (new function): user_script:7: unexpected symbol near '!'
|
18
|
+
# * Error running script:
|
19
|
+
# ** Redis 6.0, 6.2
|
20
|
+
# *** ERR Error running script (call to f_64203334c42d5690c2d008a78aa7789f5b83e5bb): @user_script:4: user_script:4: attempt to perform arithmetic on a string value
|
21
|
+
# ** Redis 7.0
|
22
|
+
# *** ERR user_script:4: attempt to perform arithmetic on a string value script: 64203334c42d5690c2d008a78aa7789f5b83e5bb, on @user_script:4.
|
23
|
+
\A
|
24
|
+
ERR\s
|
25
|
+
(?:
|
26
|
+
Error\scompiling\sscript\s\([^)]+\):\s # Redis 6.0, 6.2, 7.0
|
27
|
+
.+:(?<loc>\d+):\s # Redis 6.0, 6.2, 7.0
|
28
|
+
(?<message>.+) # Redis 6.0, 6.2, 7.0
|
29
|
+
|
|
30
|
+
(?:Error\srunning\sscript\s\([^)]+\):\s@\S+\s)? # Redis 6.0, 6.2
|
31
|
+
.+:(?<loc>\d+):\s # Redis 6.0, 6.2, 7.0
|
32
|
+
(?<message>.+?) # Redis 6.0, 6.2, 7.0
|
33
|
+
(?::\s\h+,\son\s@[^:]+:\d+\.)? # Redis 7.0
|
34
|
+
)
|
35
|
+
\z
|
36
|
+
}x
|
37
|
+
private_constant :LUA_ERROR_MESSAGE
|
38
|
+
# rubocop:enable Layout/LineLength
|
39
|
+
|
40
|
+
# Lua script source
|
14
41
|
#
|
15
42
|
# @return [String]
|
16
43
|
attr_reader :source
|
17
44
|
|
45
|
+
# Line of code where error was encountered
|
46
|
+
#
|
47
|
+
# @return [Integer?]
|
48
|
+
attr_reader :loc
|
49
|
+
|
18
50
|
# @param message [String]
|
19
|
-
# @param source [
|
51
|
+
# @param source [#to_s]
|
20
52
|
def initialize(message, source)
|
21
|
-
@source = source
|
53
|
+
@source = -source.to_s
|
54
|
+
|
55
|
+
if (parsed = LUA_ERROR_MESSAGE.match(message))
|
56
|
+
@loc = parsed[:loc].to_i
|
57
|
+
message = [parsed[:message], excerpt(@source, @loc)].compact.join("\n\n")
|
58
|
+
end
|
22
59
|
|
23
60
|
super(message)
|
24
61
|
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def excerpt(source, loc)
|
66
|
+
lines = excerpt_lines(source, loc)
|
67
|
+
gutter = lines.map(&:first).max.to_s.length
|
68
|
+
|
69
|
+
lines.map! do |(pos, line)|
|
70
|
+
format(pos == loc ? "\t%#{gutter}d > %s" : "\t%#{gutter}d | %s", pos, line).rstrip
|
71
|
+
end
|
72
|
+
|
73
|
+
lines.join("\n")
|
74
|
+
rescue => e
|
75
|
+
warn "Failed extracting source excerpt: #{e.message}"
|
76
|
+
nil
|
77
|
+
end
|
78
|
+
|
79
|
+
def excerpt_lines(source, loc)
|
80
|
+
lines = source.lines
|
81
|
+
pos = loc - 1 # reported line of code is 1-offset
|
82
|
+
min = pos - 2 # 2 lines of head context
|
83
|
+
max = pos + 2 # 2 lines of tail context
|
84
|
+
|
85
|
+
min = 0 if min.negative?
|
86
|
+
max = lines.size - 1 if lines.size <= max
|
87
|
+
|
88
|
+
(min..max).map { |i| [i.succ, lines[i]] }
|
89
|
+
end
|
25
90
|
end
|
26
91
|
end
|
data/lib/redis_prescription.rb
CHANGED
@@ -30,7 +30,7 @@ class RedisPrescription
|
|
30
30
|
# @return [String]
|
31
31
|
attr_reader :digest
|
32
32
|
|
33
|
-
# @param source [#to_s] Lua script
|
33
|
+
# @param source [#to_s] Lua script
|
34
34
|
def initialize(source)
|
35
35
|
@source = -source.to_s
|
36
36
|
@digest = Digest::SHA1.hexdigest(@source).freeze
|
@@ -46,7 +46,7 @@ class RedisPrescription
|
|
46
46
|
def call(redis, keys: EMPTY_LIST, argv: EMPTY_LIST)
|
47
47
|
unpool(redis) { |r| evalsha_with_fallback(r, keys, argv) }
|
48
48
|
rescue CommandError => e
|
49
|
-
raise ScriptError.new(e.message, @
|
49
|
+
raise ScriptError.new(e.message, @source)
|
50
50
|
end
|
51
51
|
|
52
52
|
private
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: redis-prescription
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexey Zapparov
|
@@ -35,7 +35,7 @@ metadata:
|
|
35
35
|
homepage_uri: https://gitlab.com/ixti/redis-prescription
|
36
36
|
source_code_uri: https://gitlab.com/ixti/redis-prescription
|
37
37
|
bug_tracker_uri: https://gitlab.com/ixti/redis-prescription/issues
|
38
|
-
changelog_uri: https://gitlab.com/ixti/redis-prescription/blob/v2.
|
38
|
+
changelog_uri: https://gitlab.com/ixti/redis-prescription/blob/v2.1.0/CHANGES.md
|
39
39
|
rubygems_mfa_required: 'true'
|
40
40
|
post_install_message:
|
41
41
|
rdoc_options: []
|