foobara 0.0.93 → 0.0.94

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: 447d11c02182fce4303fe2db74bbc322e0589d51161756496b2c5d8390a26eab
4
- data.tar.gz: 3a1ce551119b74488a5fe9fc86651ab914eec93f87f1d806da8f4b58135d8de7
3
+ metadata.gz: 481928c28115c1b97adee6f5caa284b559ca954ee57f337bbb456ab80972b4eb
4
+ data.tar.gz: 2d083d6fb702f82dd920e4de4a7ac9bc6e82dd3fa87d874cb89f49d495d4b780
5
5
  SHA512:
6
- metadata.gz: cf4413d689bef2063e5a43d8c88cc8f70b3d6158f722419fb613ee4a2c13560d8fff23addd5cc34d4f18ad7c6437435d5382f205b6aa53904888354e6cb0de04
7
- data.tar.gz: 761d8e8de14d04d5ca8c2916c23ead8cc261ca8b641584083ef2cb25e9fc9a621515be5a5524d41c97b0a867d829ae8b8cd802b6935b152b9ae8ef55ec9c6944
6
+ metadata.gz: 2c9a25149a21e5d8aa851e4a8776f5f3d8a3e44635598544a4d9da2e8e9709ec61c812e286ecedacd6376e7a928c94993567a5dd00d0c67d829d4f6a4d9848f6
7
+ data.tar.gz: 9561f972da6f0c94e40adc04d23ef33e7eea856b045248c4e04f057365543eaf82b6810592221e64e1ecb9e3a31530edb2f7beefa2ab3845a117197bd0b6c6af
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.0.94] - 2025-04-07
2
+
3
+ - Support capture_unknown_errors at the command connector level
4
+
1
5
  # [0.0.93] - 2025-04-06
2
6
 
3
7
  - Add delegated attributes to models
@@ -74,7 +74,13 @@ module Foobara
74
74
  end
75
75
 
76
76
  def outcome
77
- command.outcome
77
+ outcome = command&.outcome
78
+
79
+ if outcome
80
+ outcome
81
+ elsif error
82
+ Outcome.error(error)
83
+ end
78
84
  end
79
85
 
80
86
  def result
@@ -11,7 +11,13 @@ module Foobara
11
11
  self.body = body
12
12
  end
13
13
 
14
- foobara_delegate :command, :error, to: :request
14
+ def command
15
+ request.command
16
+ end
17
+
18
+ def success?
19
+ request.success?
20
+ end
15
21
  end
16
22
  end
17
23
  end
@@ -86,6 +86,18 @@ module Foobara
86
86
  end
87
87
  end
88
88
 
89
+ attr_accessor :command_registry, :authenticator, :capture_unknown_error
90
+
91
+ def initialize(authenticator: nil, capture_unknown_error: nil, default_serializers: nil)
92
+ self.command_registry = CommandRegistry.new(authenticator:)
93
+ self.authenticator = authenticator
94
+ self.capture_unknown_error = capture_unknown_error
95
+
96
+ Util.array(default_serializers).each do |serializer|
97
+ add_default_serializer(serializer)
98
+ end
99
+ end
100
+
89
101
  def find_builtin_command_class(command_class_name)
90
102
  self.class.find_builtin_command_class(command_class_name)
91
103
  end
@@ -104,8 +116,6 @@ module Foobara
104
116
  :all_transformed_command_classes,
105
117
  to: :command_registry
106
118
 
107
- attr_accessor :command_registry, :authenticator
108
-
109
119
  def lookup_command(name)
110
120
  command_registry.foobara_lookup_command(name)
111
121
  end
@@ -237,13 +247,11 @@ module Foobara
237
247
  end
238
248
 
239
249
  def set_response_status(response)
240
- outcome = response.request.outcome
241
- response.status = outcome.success? ? 0 : 1
250
+ response.status = response.success? ? 0 : 1
242
251
  end
243
252
 
244
253
  def set_response_body(response)
245
254
  outcome = response.request.outcome
246
- # response.body = outcome.success? ? outcome.result : outcome.error_collection
247
255
  response.body = outcome.success? ? outcome.result : outcome.error_collection
248
256
  end
249
257
 
@@ -263,15 +271,6 @@ module Foobara
263
271
  end
264
272
  end
265
273
 
266
- def initialize(authenticator: nil, default_serializers: nil)
267
- self.command_registry = CommandRegistry.new(authenticator:)
268
- self.authenticator = authenticator
269
-
270
- Util.array(default_serializers).each do |serializer|
271
- add_default_serializer(serializer)
272
- end
273
- end
274
-
275
274
  def connect_delayed(registerable_name, *args, **opts)
276
275
  delayed_connections[registerable_name] = { args:, opts: }
277
276
  end
@@ -343,7 +342,7 @@ module Foobara
343
342
  end
344
343
 
345
344
  if command
346
- command.run
345
+ run_command(request)
347
346
  # :nocov:
348
347
  elsif !request.error
349
348
  raise "No command returned from #request_to_command"
@@ -353,6 +352,16 @@ module Foobara
353
352
  build_response(request)
354
353
  end
355
354
 
355
+ def run_command(request)
356
+ request.command.run
357
+ rescue => e
358
+ if capture_unknown_error
359
+ request.error = CommandConnector::UnknownError.new(e)
360
+ else
361
+ raise
362
+ end
363
+ end
364
+
356
365
  def authenticate(request)
357
366
  request_command = request.command
358
367
 
@@ -113,6 +113,7 @@ module Foobara
113
113
  def transformed_command_class
114
114
  @transformed_command_class ||= if Util.all_blank_or_false?(
115
115
  [
116
+ capture_unknown_error,
116
117
  inputs_transformers,
117
118
  result_transformers,
118
119
  errors_transformers,
@@ -4,8 +4,10 @@ module Foobara
4
4
  module CommandConnectors
5
5
  module Serializers
6
6
  class ErrorsSerializer < Serializer
7
- def always_applicable?
8
- !request.outcome.success?
7
+ def applicable?(error_collection)
8
+ if request.outcome.nil? || !request.outcome.success?
9
+ error_collection.has_errors?
10
+ end
9
11
  end
10
12
 
11
13
  def serialize(error_collection)
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.93
4
+ version: 0.0.94
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-04-06 00:00:00.000000000 Z
10
+ date: 2025-04-07 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: bigdecimal
@@ -487,7 +487,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
487
487
  - !ruby/object:Gem::Version
488
488
  version: '0'
489
489
  requirements: []
490
- rubygems_version: 3.6.6
490
+ rubygems_version: 3.6.2
491
491
  specification_version: 4
492
492
  summary: A command-centric and discoverable software framework with a focus on domain
493
493
  concepts and abstracting away integration code