lite-command 3.1.0 → 3.1.1
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/CHANGELOG.md +4 -0
- data/Gemfile.lock +1 -1
- data/README.md +28 -10
- data/lib/lite/command/fault_streamer.rb +22 -11
- data/lib/lite/command/internals/calls.rb +3 -1
- data/lib/lite/command/internals/executions.rb +2 -2
- data/lib/lite/command/internals/faults.rb +4 -5
- data/lib/lite/command/version.rb +1 -1
- 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: 6239fda55d099d36d3fc4c171ecf6eff2cd56bb5ffc4536dde420da339d0b5c9
|
4
|
+
data.tar.gz: a7c3949c9313a479f16f4cf709730f8262576f4d899069240073c52923c9aac3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6330c34c333948919685049c4eaefc5913ab364b09f28322ea6283aa73b3906715cc063b1b61192e231d5582206e0ae91be506fba09035317711dd56ad7f7ae2
|
7
|
+
data.tar.gz: 69a682501448fb31fd0ad5709fc23f5f8b5dabc3c9a01486c4848a1d01f887523ab3fee3e7c2acdf6861b181bc1347dbee9bdccd6af3f1dc21321a6585a0a0f4
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
+
## [3.1.1] - 2024-10-25
|
10
|
+
### Changed
|
11
|
+
- Add option to raise original or fault exception
|
12
|
+
|
9
13
|
## [3.1.0] - 2024-10-25
|
10
14
|
### Added
|
11
15
|
- Added `raise!` method to reraise soft call errors
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -26,6 +26,7 @@ Or install it yourself as:
|
|
26
26
|
* [Usage](#usage)
|
27
27
|
* [Execution](#execution)
|
28
28
|
* [Dynamic Faults](#dynamic-faults)
|
29
|
+
* [Raising Faults](#raising-faults)
|
29
30
|
* [Context](#context)
|
30
31
|
* [Attributes](#attributes)
|
31
32
|
* [Validations](#validations)
|
@@ -88,21 +89,15 @@ end
|
|
88
89
|
|
89
90
|
Executing a command can be done as an instance or class call. It returns the command instance
|
90
91
|
in a frozen state. These will never call will never raise an execption, but will be kept track
|
91
|
-
of in its internal state.
|
92
|
+
of in its internal state.
|
92
93
|
|
93
94
|
```ruby
|
94
|
-
|
95
|
+
DecryptSecretMessage.call(...)
|
95
96
|
# - or -
|
96
|
-
|
97
|
+
DecryptSecretMessage.new(...).call
|
97
98
|
|
98
99
|
# On success, fault or exception:
|
99
|
-
|
100
|
-
|
101
|
-
# On fault:
|
102
|
-
cmd.raise! #=> raises Lite::Command::Fault
|
103
|
-
|
104
|
-
# On exception:
|
105
|
-
cmd.raise! #=> raises StandardError
|
100
|
+
#=> <DecryptSecretMessage ...>
|
106
101
|
```
|
107
102
|
|
108
103
|
> [!TIP]
|
@@ -127,6 +122,29 @@ DecryptSecretMessage.new(...).call!
|
|
127
122
|
#=> raises StandardError
|
128
123
|
```
|
129
124
|
|
125
|
+
### Raising Faults
|
126
|
+
|
127
|
+
Sometimes its suitable to raise the offending soft call command fault later
|
128
|
+
in a call stack. Use the `raise!` method to reraise the fault or original
|
129
|
+
error (if they differ). `original: false` is the default.
|
130
|
+
|
131
|
+
```ruby
|
132
|
+
cmd = DecryptSecretMessage.call(...)
|
133
|
+
Apm.track_stat("DecryptSecretMessage.called")
|
134
|
+
# other stuff...
|
135
|
+
|
136
|
+
# On success:
|
137
|
+
cmd.raise! #=> nil
|
138
|
+
|
139
|
+
# On fault:
|
140
|
+
cmd.raise!(original: false) #=> raises Lite::Command::Fault
|
141
|
+
cmd.raise!(original: true) #=> raises Lite::Command::Fault
|
142
|
+
|
143
|
+
# On exception:
|
144
|
+
cmd.raise!(original: false) #=> raises Lite::Command::Error
|
145
|
+
cmd.raise!(original: true) #=> raises StandardError
|
146
|
+
```
|
147
|
+
|
130
148
|
### Dynamic Faults
|
131
149
|
|
132
150
|
Dynamic faults are custom faults named after your command. This is especially
|
@@ -11,6 +11,20 @@ module Lite
|
|
11
11
|
@object = object
|
12
12
|
end
|
13
13
|
|
14
|
+
def reason
|
15
|
+
if object.respond_to?(:reason)
|
16
|
+
object.reason
|
17
|
+
elsif object.is_a?(StandardError)
|
18
|
+
"[#{object.class.name}] #{object.message}".chomp(".")
|
19
|
+
else
|
20
|
+
object
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def metadata
|
25
|
+
Utils.try(object, :metadata) || command.metadata
|
26
|
+
end
|
27
|
+
|
14
28
|
def caused_by
|
15
29
|
Utils.try(object, :caused_by) || command
|
16
30
|
end
|
@@ -21,18 +35,15 @@ module Lite
|
|
21
35
|
Utils.try(object, :thrown_by) || command.caused_by
|
22
36
|
end
|
23
37
|
|
24
|
-
def
|
25
|
-
|
26
|
-
end
|
38
|
+
def fault_exception
|
39
|
+
return if command.success?
|
27
40
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
object
|
35
|
-
end
|
41
|
+
Fault.build(
|
42
|
+
command.status.capitalize,
|
43
|
+
command,
|
44
|
+
object,
|
45
|
+
dynamic: command.send(:raise_dynamic_faults?)
|
46
|
+
)
|
36
47
|
end
|
37
48
|
|
38
49
|
end
|
@@ -84,13 +84,15 @@ module Lite
|
|
84
84
|
@metadata ||= down_stream.metadata
|
85
85
|
@caused_by ||= down_stream.caused_by
|
86
86
|
@thrown_by ||= down_stream.thrown_by
|
87
|
+
|
88
|
+
@fault_exception ||= down_stream.fault_exception
|
87
89
|
end
|
88
90
|
|
89
91
|
FAULTS.each do |f|
|
90
92
|
# eg: invalid!("idk") or failure!(fault) or error!("idk", { error_key: "some.error" })
|
91
93
|
define_method(:"#{f}!") do |object, metadata = nil|
|
92
94
|
fault(object, f, metadata)
|
93
|
-
raise
|
95
|
+
raise(fault_exception)
|
94
96
|
end
|
95
97
|
end
|
96
98
|
|
@@ -60,7 +60,7 @@ module Lite
|
|
60
60
|
around_execution { call }
|
61
61
|
Utils.try(self, :on_success)
|
62
62
|
rescue StandardError => e
|
63
|
-
@
|
63
|
+
@original_exception = e
|
64
64
|
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
65
65
|
after_execution
|
66
66
|
Utils.try(self, :"on_#{status}", e)
|
@@ -72,7 +72,7 @@ module Lite
|
|
72
72
|
around_execution { call }
|
73
73
|
Utils.try(self, :on_success)
|
74
74
|
rescue StandardError => e
|
75
|
-
@
|
75
|
+
@original_exception = e
|
76
76
|
fault(e, ERROR, metadata) unless e.is_a?(Lite::Command::Fault)
|
77
77
|
after_execution
|
78
78
|
Utils.try(self, :"on_#{status}", e)
|
@@ -6,7 +6,7 @@ module Lite
|
|
6
6
|
module Faults
|
7
7
|
|
8
8
|
def self.included(base)
|
9
|
-
base.class_eval { attr_reader :
|
9
|
+
base.class_eval { attr_reader :fault_exception, :original_exception }
|
10
10
|
end
|
11
11
|
|
12
12
|
def caused_by
|
@@ -33,10 +33,9 @@ module Lite
|
|
33
33
|
fault? && !caused_fault?
|
34
34
|
end
|
35
35
|
|
36
|
-
def raise!
|
37
|
-
|
38
|
-
|
39
|
-
raise exception
|
36
|
+
def raise!(original: false)
|
37
|
+
exception = (fault_exception unless original) || original_exception
|
38
|
+
raise(exception) unless exception.nil?
|
40
39
|
end
|
41
40
|
|
42
41
|
private
|
data/lib/lite/command/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-command
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.1.
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|