Exception: Foobara::Error
- Inherits:
-
StandardError
- Object
- StandardError
- Foobara::Error
show all
- Includes:
- Manifestable
- Defined in:
- foobara-0.5.8/projects/typesystem/projects/common/src/error.rb,
foobara-0.5.8/projects/typesystem/projects/types/src/extensions/error.rb
Direct Known Subclasses
CommandConnectors::ShCliConnector::ParseError, McpConnector::JsonrpcRequest::EmptyBatchError, McpConnector::JsonrpcRequest::InvalidJsonError, McpConnector::JsonrpcRequest::InvalidJsonrpcMethodError, McpConnector::JsonrpcRequest::InvalidJsonrpcParamsError, McpConnector::JsonrpcRequest::InvalidJsonrpcRequestStructureError, McpConnector::JsonrpcRequest::InvalidJsonrpcVersionError, McpConnector::Request::FoobaraCommandsDoNotAcceptArraysError, McpConnector::Request::MethodNotYetSupportedError, RuntimeError, Value::DataError
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Concern
foobara_class_methods_module_for, foobara_concern?, included
Constructor Details
#initialize(path: self.class.path, runtime_path: self.class.runtime_path, category: self.class.category, message: self.class.message, symbol: self.class.symbol, context: self.class.context, is_fatal: self.class.fatal?) ⇒ Error
TODO: seems like we should not allow the symbol to vary within instances of a class TODO: any items serializable in self.class.to_h should not be overrideable like this…
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
# File 'projects/typesystem/projects/common/src/error.rb', line 227
def initialize(
path: self.class.path,
runtime_path: self.class.runtime_path,
category: self.class.category,
message: self.class.message,
symbol: self.class.symbol,
context: self.class.context,
is_fatal: self.class.fatal?
)
self.error_key = ErrorKey.new
self.symbol = symbol
self.message = message
self.context = context
self.category = category
if path.is_a?(::String) || path.is_a?(::Symbol)
path = path.to_s.split(".").map(&:to_sym)
end
self.path = path
self.runtime_path = runtime_path
self.is_fatal = is_fatal
if !self.message.is_a?(String) || self.message.empty?
raise "Bad error message, expected a string"
end
backtrace_when_initialized = caller[1..]
index = 1
has_build_error = false
1.upto(10) do |i|
backtrace_line = backtrace_when_initialized[i]
break unless backtrace_line
if backtrace_when_initialized[i].end_with?("#build_error'")
index = i + 1
has_build_error = true
break
end
end
if has_build_error
index.upto(10) do |i|
unless backtrace_when_initialized[i].end_with?("#build_error'")
index = i
break
end
end
end
self.backtrace_when_initialized = backtrace_when_initialized[index..]
super(message)
end
|
Instance Attribute Details
#backtrace_when_initialized ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def backtrace_when_initialized
@backtrace_when_initialized
end
|
#backtrace_when_raised ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def backtrace_when_raised
@backtrace_when_raised
end
|
#context ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def context
@context
end
|
#error_key ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def error_key
@error_key
end
|
#is_fatal ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def is_fatal
@is_fatal
end
|
#message ⇒ Object
TODO: rename :path to data_path
10
11
12
|
# File 'projects/typesystem/projects/common/src/error.rb', line 10
def message
@message
end
|
Class Method Details
.abstract ⇒ Object
15
16
17
|
# File 'projects/typesystem/projects/common/src/error.rb', line 15
def abstract
@abstract = true
end
|
.abstract? ⇒ Boolean
19
20
21
|
# File 'projects/typesystem/projects/common/src/error.rb', line 19
def abstract?
@abstract
end
|
.category ⇒ Object
50
51
52
|
# File 'projects/typesystem/projects/common/src/error.rb', line 50
def category
nil
end
|
.context(*args, &block) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
# File 'projects/typesystem/projects/common/src/error.rb', line 72
def context(*args, &block)
if block_given?
args = [*args, block]
end
args_size = args.size
case args_size
when 0
{}
when 1
arg = args.first
singleton_class.define_method :context_type_declaration do
arg
end
else
raise ArgumentError, "expected 0 or 1 argument, got #{args_size}"
end
end
|
.fatal? ⇒ Boolean
93
94
95
|
# File 'projects/typesystem/projects/common/src/error.rb', line 93
def fatal?
false
end
|
.foobara_manifest ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
# File 'projects/typesystem/projects/common/src/error.rb', line 107
def foobara_manifest
to_include = TypeDeclarations.foobara_manifest_context_to_include
types = types_depended_on.map do |t|
if to_include
to_include << t
end
t.foobara_manifest_reference
end
base = nil
unless superclass == Foobara::Error
base = superclass
if to_include
to_include << base
end
end
manifest = super
unless types.empty?
manifest[:types_depended_on] = types.sort
end
h = manifest.merge(Util.remove_blank(to_h)).merge(
error_class: name
)
if base
h[:base_error] = base.foobara_manifest_reference
end
if abstract?
h[:abstract] = true
end
h
end
|
.message(*args) ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'projects/typesystem/projects/common/src/error.rb', line 54
def message(*args)
args_size = args.size
case args_size
when 0
Util.humanize(symbol.to_s)
when 1
arg = args.first
singleton_class.define_method :message do
arg
end
else
raise ArgumentError, "expected 0 or 1 argument, got #{args_size}"
end
end
|
.path ⇒ Object
42
43
44
|
# File 'projects/typesystem/projects/common/src/error.rb', line 42
def path
ErrorKey::EMPTY_PATH
end
|
.runtime_path ⇒ Object
46
47
48
|
# File 'projects/typesystem/projects/common/src/error.rb', line 46
def runtime_path
ErrorKey::EMPTY_PATH
end
|
.subclass(context: {}, name: nil, symbol: nil, message: nil, base_error: self, mod: base_error, category: base_error.category, is_fatal: false, abstract: false) ⇒ Object
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'projects/typesystem/projects/common/src/error.rb', line 147
def subclass(
context: {},
name: nil,
symbol: nil,
message: nil,
base_error: self,
mod: base_error,
category: base_error.category,
is_fatal: false,
abstract: false
)
name ||= [*mod.name, "#{Util.classify(symbol)}Error"].join("::")
klass = Util.make_class_p(name, base_error) do
singleton_class.define_method :category do
category
end
if symbol
singleton_class.define_method :symbol do
symbol
end
end
singleton_class.define_method :fatal? do
is_fatal
end
singleton_class.define_method :context_type_declaration do
context
end
if message
singleton_class.define_method :message do
message
end
end
end
klass.abstract if abstract
klass
end
|
.symbol(*args) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'projects/typesystem/projects/common/src/error.rb', line 23
def symbol(*args)
args_size = args.size
case args_size
when 0
Util.non_full_name_underscore(self).gsub(/_error$/, "").to_sym
when 1
arg = args.first
singleton_class.define_method :symbol do
arg
end
else
raise ArgumentError, "expected 0 or 1 argument, got #{args_size}"
end
end
|
.to_h ⇒ Object
97
98
99
100
101
102
103
104
105
|
# File 'projects/typesystem/projects/common/src/error.rb', line 97
def to_h
{
category:,
symbol:,
context_type_declaration: context_type&.declaration_data,
is_fatal: fatal?
}
end
|
.types_depended_on(*args) ⇒ Object
Instance Method Details
#==(other) ⇒ Object
296
297
298
|
# File 'projects/typesystem/projects/common/src/error.rb', line 296
def ==(other)
equal?(other) || eql?(other)
end
|
#category ⇒ Object
201
202
203
|
# File 'projects/typesystem/projects/common/src/error.rb', line 201
def category
error_key.category
end
|
#category=(category) ⇒ Object
205
206
207
|
# File 'projects/typesystem/projects/common/src/error.rb', line 205
def category=(category)
error_key.category = category
end
|
#eql?(other) ⇒ Boolean
300
301
302
303
304
|
# File 'projects/typesystem/projects/common/src/error.rb', line 300
def eql?(other)
return false unless other.is_a?(Error)
symbol == other.symbol
end
|
#fatal? ⇒ Boolean
288
289
290
|
# File 'projects/typesystem/projects/common/src/error.rb', line 288
def fatal?
is_fatal
end
|
#key ⇒ Object
292
293
294
|
# File 'projects/typesystem/projects/common/src/error.rb', line 292
def key
error_key.to_s
end
|
#path ⇒ Object
209
210
211
|
# File 'projects/typesystem/projects/common/src/error.rb', line 209
def path
error_key.path
end
|
#path=(path) ⇒ Object
213
214
215
|
# File 'projects/typesystem/projects/common/src/error.rb', line 213
def path=(path)
error_key.path = path
end
|
#prepend_path! ⇒ Object
306
307
308
309
|
# File 'projects/typesystem/projects/common/src/error.rb', line 306
def prepend_path!(...)
error_key.prepend_path!(...)
self
end
|
#runtime_path ⇒ Object
193
194
195
|
# File 'projects/typesystem/projects/common/src/error.rb', line 193
def runtime_path
error_key.runtime_path
end
|
#runtime_path=(runtime_path) ⇒ Object
197
198
199
|
# File 'projects/typesystem/projects/common/src/error.rb', line 197
def runtime_path=(runtime_path)
error_key.runtime_path = runtime_path
end
|
#symbol ⇒ Object
217
218
219
|
# File 'projects/typesystem/projects/common/src/error.rb', line 217
def symbol
error_key.symbol
end
|
#symbol=(symbol) ⇒ Object
221
222
223
|
# File 'projects/typesystem/projects/common/src/error.rb', line 221
def symbol=(symbol)
error_key.symbol = symbol
end
|
#to_h ⇒ Object
311
312
313
314
315
316
317
318
319
320
321
322
|
# File 'projects/typesystem/projects/common/src/error.rb', line 311
def to_h
{
key:,
path:,
runtime_path:,
category:,
symbol:,
message:,
context:,
is_fatal: fatal?
}
end
|