foobara 0.0.106 → 0.0.107

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: 980071302c992808e812a703ff9a203fca501336c00225dd8eeb045982975704
4
- data.tar.gz: '04901d96e1717a09d736feccd2c21d31873ae32235362b0613476f508423373f'
3
+ metadata.gz: a8a5a11223a3bc2f8aebf691c6bc8f0d0bdb05930286f9c1e16f2f1ac8f82756
4
+ data.tar.gz: 07f8edc98723f2297413d12065483d0a80f1b641ca0088fab99434c59cba4d4c
5
5
  SHA512:
6
- metadata.gz: cee4fbf405088f382583642aed0c40c55010249e346f6881608463ec37d8bd8fe378fe030adedc3c2c1534a89980ee475affa872e260e7e95dbad611411d84f8
7
- data.tar.gz: 741ed3a774a1d92dacef4a640706b41764f10144d39b130eeaf032648a60d95b3d450830facd8334b346a1a2e07179b750899063e69ac3bb1e6862884a0bff64
6
+ metadata.gz: 4a75a392d55df8390b3d483b8a1d670d0b466783921fe2808961c18d4587644e82f515734cf49fac1ae9d42c8ed19a084d3562131e70ec9259ea5cdfaee945f1
7
+ data.tar.gz: 939caca7112b46752613e9427471c1c0dc0d422fd24d571d379973bae3a169f71816cbbffb0df2ff939a213c7bc16ae104c6416d3c0f3003ce96be5a748aca52
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # [0.0.107] - 2025-04-22
2
+
3
+ - Make sure various Foobara::Error subclasses have consistent interfaces
4
+
1
5
  # [0.0.106] - 2025-04-20
2
6
 
3
7
  - Fix authenticator explanation that was coupled to pry
@@ -72,7 +72,7 @@ module Foobara
72
72
 
73
73
  thunks_to_load
74
74
  rescue Entity::NotFoundError => e
75
- add_runtime_error(error_class.new(e.criteria))
75
+ add_runtime_error(error_class.for(e.criteria))
76
76
  end
77
77
  end
78
78
 
@@ -581,7 +581,7 @@ module Foobara
581
581
  explanation = source || "No explanation."
582
582
  end
583
583
 
584
- error = CommandConnector::NotAllowedError.new(rule_symbol: rule.symbol, explanation:)
584
+ error = CommandConnector::NotAllowedError.for(rule_symbol: rule.symbol, explanation:)
585
585
  self.outcome = Outcome.error(error)
586
586
 
587
587
  command.state_machine.error!
@@ -605,7 +605,7 @@ module Foobara
605
605
  rescue => e
606
606
  if capture_unknown_error
607
607
  # TODO: move to superclass?
608
- self.outcome = Outcome.error(CommandConnector::UnknownError.new(e))
608
+ self.outcome = Outcome.error(CommandConnector::UnknownError.for(e))
609
609
  else
610
610
  # :nocov:
611
611
  raise
@@ -0,0 +1,11 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class CommandConnectorError < Foobara::RuntimeError
4
+ context({})
5
+
6
+ def initialize(message:, context: {})
7
+ super
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,5 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class InvalidContextError < CommandConnectorError; end
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class NoCommandFoundError < NotFoundError; end
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ require_relative "not_found_error"
2
+
3
+ module Foobara
4
+ class CommandConnector
5
+ class NoCommandOrTypeFoundError < NotFoundError; end
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class NoTypeFoundError < NotFoundError; end
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class NotAllowedError < CommandConnectorError
4
+ class << self
5
+ def for(rule_symbol: nil, explanation: nil)
6
+ rule_symbol ||= :no_symbol_declared
7
+ message = "Not allowed"
8
+ if explanation
9
+ message += ": #{explanation}"
10
+ end
11
+ explanation ||= "No explanation"
12
+ context = { rule_symbol:, explanation: }
13
+
14
+ new(message:, context:)
15
+ end
16
+ end
17
+
18
+ context do
19
+ rule_symbol :symbol, :required
20
+ explanation :string, :required
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require_relative "command_connector_error"
2
+
3
+ module Foobara
4
+ class CommandConnector
5
+ class NotFoundError < CommandConnectorError
6
+ context not_found: :string
7
+
8
+ def initialize(message: "Not found: #{context[:not_found]}", **)
9
+ super
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class UnauthenticatedError < CommandConnectorError
4
+ def initialize(message: "Unauthenticated", **)
5
+ super
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ module Foobara
2
+ class CommandConnector
3
+ class UnknownError < CommandConnectorError
4
+ class << self
5
+ def for(error)
6
+ new(message: error.message).tap do |unknown_error|
7
+ unknown_error.error = error
8
+ end
9
+ end
10
+ end
11
+
12
+ attr_accessor :error
13
+ end
14
+ end
15
+ end
@@ -2,84 +2,6 @@ module Foobara
2
2
  class CommandConnector
3
3
  class UnexpectedSensitiveTypeInManifestError < StandardError; end
4
4
 
5
- class CommandConnectorError < Foobara::RuntimeError
6
- class << self
7
- def context_type_declaration
8
- {}
9
- end
10
- end
11
-
12
- def initialize(message, context: {})
13
- super(message:, context:)
14
- end
15
- end
16
-
17
- class UnknownError < CommandConnectorError
18
- attr_accessor :error
19
-
20
- def initialize(error)
21
- # TODO: can we just use #cause for this?
22
- self.error = error
23
-
24
- super(error.message)
25
- end
26
- end
27
-
28
- class NotFoundError < CommandConnectorError
29
- class << self
30
- def context_type_declaration
31
- { not_found: :string }
32
- end
33
- end
34
-
35
- attr_accessor :not_found
36
-
37
- def initialize(not_found)
38
- self.not_found = not_found
39
-
40
- super(message, context: { not_found: })
41
- end
42
-
43
- def message
44
- "Not found: #{not_found}"
45
- end
46
- end
47
-
48
- class UnauthenticatedError < CommandConnectorError
49
- def initialize
50
- super("Unauthenticated")
51
- end
52
- end
53
-
54
- class NotAllowedError < CommandConnectorError
55
- class << self
56
- def context_type_declaration
57
- {
58
- rule_symbol: :symbol,
59
- explanation: :string
60
- }
61
- end
62
- end
63
-
64
- attr_accessor :rule_symbol, :explanation
65
-
66
- def initialize(rule_symbol:, explanation:)
67
- self.rule_symbol = rule_symbol || :no_symbol_declared
68
- self.explanation = explanation || "No explanation"
69
-
70
- super("Not allowed: #{explanation}", context:)
71
- end
72
-
73
- def context
74
- { rule_symbol:, explanation: }
75
- end
76
- end
77
-
78
- class InvalidContextError < CommandConnectorError; end
79
- class NoCommandFoundError < NotFoundError; end
80
- class NoTypeFoundError < NotFoundError; end
81
- class NoCommandOrTypeFoundError < NotFoundError; end
82
-
83
5
  class << self
84
6
  def find_builtin_command_class(command_class_name)
85
7
  Util.find_constant_through_class_hierarchy(self, "Commands::#{command_class_name}")
@@ -231,7 +153,7 @@ module Foobara
231
153
 
232
154
  unless transformed_command_class
233
155
  # :nocov:
234
- raise NoCommandFoundError, "Could not find command registered for #{full_command_name}"
156
+ raise NoCommandFoundError.new(message: "Could not find command registered for #{full_command_name}")
235
157
  # :nocov:
236
158
  end
237
159
 
@@ -243,7 +165,9 @@ module Foobara
243
165
 
244
166
  unless manifestable
245
167
  # :nocov:
246
- raise NoCommandOrTypeFoundError, "Could not find command or type registered for #{full_command_name}"
168
+ raise NoCommandOrTypeFoundError.new(
169
+ message: "Could not find command or type registered for #{full_command_name}"
170
+ )
247
171
  # :nocov:
248
172
  end
249
173
 
@@ -259,7 +183,7 @@ module Foobara
259
183
 
260
184
  unless transformed_command_class
261
185
  # :nocov:
262
- raise NoCommandFoundError, "Could not find command registered for #{full_command_name}"
186
+ raise NoCommandFoundError.new(message: "Could not find command registered for #{full_command_name}")
263
187
  # :nocov:
264
188
  end
265
189
 
@@ -274,7 +198,7 @@ module Foobara
274
198
 
275
199
  unless type
276
200
  # :nocov:
277
- raise NoTypeFoundError, "Could not find type registered for #{full_command_name}"
201
+ raise NoTypeFoundError.new(message: "Could not find type registered for #{full_command_name}")
278
202
  # :nocov:
279
203
  end
280
204
 
@@ -323,7 +247,7 @@ module Foobara
323
247
  transform_command_class(command_class)
324
248
  else
325
249
  # :nocov:
326
- raise InvalidContextError, "Not sure what to do with #{action}"
250
+ raise InvalidContextError.new(message: "Not sure what to do with #{action}")
327
251
  # :nocov:
328
252
  end
329
253
 
@@ -466,7 +390,7 @@ module Foobara
466
390
  request.command.run
467
391
  rescue => e
468
392
  if capture_unknown_error
469
- request.error = CommandConnector::UnknownError.new(e)
393
+ request.error = CommandConnector::UnknownError.for(e)
470
394
  else
471
395
  raise
472
396
  end
@@ -55,7 +55,7 @@ module Foobara
55
55
  record
56
56
  end
57
57
 
58
- raise NotFoundError.new(primary_key, entity_class: self)
58
+ raise NotFoundError.for(primary_key, entity_class: self)
59
59
  end
60
60
 
61
61
  def load_aggregate(record_or_record_id)
@@ -31,41 +31,40 @@ module Foobara
31
31
  end
32
32
  end
33
33
 
34
- def data_path
35
- nil
34
+ def for(criteria, entity_class: self.entity_class, data_path: self.data_path || "")
35
+ message = "Could not find #{entity_class} for #{criteria}"
36
+ context = {
37
+ entity_class: entity_class.full_entity_name,
38
+ criteria:,
39
+ data_path: data_path.to_s
40
+ }
41
+
42
+ new(context:, message:)
36
43
  end
37
44
 
38
- def context_type_declaration
39
- {
40
- entity_class: :string, # TODO: we don't have a way to specify an exact value for a type
41
- criteria: :duck, # TODO: probably should be integer or string but no union types yet
42
- data_path: :string # TODO: we don't have a way to specify an exact value for a type
43
- }
45
+ def data_path
46
+ nil
44
47
  end
45
48
  end
46
49
 
47
- attr_accessor :data_path, :entity_class, :criteria
50
+ context do
51
+ entity_class :string # TODO: we don't have a way to specify an exact value for a type
52
+ criteria :duck # TODO: probably should be integer or string but no union types yet
53
+ data_path :string # TODO: we don't have a way to specify an exact value for a type
54
+ end
48
55
 
49
56
  foobara_delegate :primary_key_attribute, :full_entity_name, to: :entity_class
50
57
 
51
- def initialize(criteria, entity_class: self.class.entity_class, data_path: self.class.data_path)
52
- self.criteria = criteria
53
- self.entity_class = entity_class
54
- self.data_path = data_path || ""
55
-
56
- super(context:, message:)
58
+ def criteria
59
+ context[:criteria]
57
60
  end
58
61
 
59
- def context
60
- {
61
- entity_class: full_entity_name,
62
- criteria:,
63
- data_path: data_path.to_s
64
- }
62
+ def data_path
63
+ context[:data_path]
65
64
  end
66
65
 
67
- def message
68
- "Could not find #{entity_class} for #{criteria}"
66
+ def entity_class
67
+ context[:entity_class]
69
68
  end
70
69
  end
71
70
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foobara
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.106
4
+ version: 0.0.107
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miles Georgi
@@ -183,12 +183,21 @@ files:
183
183
  - projects/command_connectors/lib/foobara/command_connectors.rb
184
184
  - projects/command_connectors/src/authenticator.rb
185
185
  - projects/command_connectors/src/command_connector.rb
186
+ - projects/command_connectors/src/command_connector/command_connector_error.rb
186
187
  - projects/command_connectors/src/command_connector/commands/describe.rb
187
188
  - projects/command_connectors/src/command_connector/commands/list_commands.rb
188
189
  - projects/command_connectors/src/command_connector/commands/ping.rb
189
190
  - projects/command_connectors/src/command_connector/commands/query_git_commit_info.rb
191
+ - projects/command_connectors/src/command_connector/invalid_context_error.rb
192
+ - projects/command_connectors/src/command_connector/no_command_found_error.rb
193
+ - projects/command_connectors/src/command_connector/no_command_or_type_found_error.rb
194
+ - projects/command_connectors/src/command_connector/no_type_found_error.rb
195
+ - projects/command_connectors/src/command_connector/not_allowed_error.rb
196
+ - projects/command_connectors/src/command_connector/not_found_error.rb
190
197
  - projects/command_connectors/src/command_connector/request.rb
191
198
  - projects/command_connectors/src/command_connector/response.rb
199
+ - projects/command_connectors/src/command_connector/unauthenticated_error.rb
200
+ - projects/command_connectors/src/command_connector/unknown_error.rb
192
201
  - projects/command_connectors/src/command_registry.rb
193
202
  - projects/command_connectors/src/command_registry/allowed_rule.rb
194
203
  - projects/command_connectors/src/command_registry/exposed_command.rb