@@ -119,14 +119,6 @@ impl ScriptError {
119
119
} ) )
120
120
}
121
121
122
- pub fn with_context < S : ToString > ( self , context : S ) -> Self {
123
- Self ( Arc :: new ( ScriptErrorInner {
124
- script : self . 0 . script . clone ( ) ,
125
- context : context. to_string ( ) ,
126
- reason : self . 0 . reason . clone ( ) ,
127
- } ) )
128
- }
129
-
130
122
pub fn with_script < S : ToString > ( self , script : S ) -> Self {
131
123
Self ( Arc :: new ( ScriptErrorInner {
132
124
script : Some ( script. to_string ( ) ) ,
@@ -135,10 +127,10 @@ impl ScriptError {
135
127
} ) )
136
128
}
137
129
138
- pub fn with_appended_context < S : ToString > ( self , context : S ) -> Self {
130
+ pub fn with_context < S : ToString > ( self , context : S ) -> Self {
139
131
Self ( Arc :: new ( ScriptErrorInner {
140
132
script : self . 0 . script . clone ( ) ,
141
- context : format ! ( "{}. {}" , self . 0 . context, context. to_string( ) ) ,
133
+ context : format ! ( "{}\n {}" , self . 0 . context, context. to_string( ) ) ,
142
134
reason : self . 0 . reason . clone ( ) ,
143
135
} ) )
144
136
}
@@ -149,11 +141,11 @@ impl std::fmt::Display for ScriptError {
149
141
if let Some ( script) = & self . 0 . script {
150
142
write ! (
151
143
f,
152
- "error in script `{}`: {}.\n {}" ,
144
+ "error in script `{}`: {}.\n Context: {}" ,
153
145
script, self . 0 . reason, self . 0 . context
154
146
)
155
147
} else {
156
- write ! ( f, "error: {}.\n {}" , self . 0 . reason, self . 0 . context)
148
+ write ! ( f, "error: {}.\n Context: {}" , self . 0 . reason, self . 0 . context)
157
149
}
158
150
}
159
151
}
@@ -162,14 +154,14 @@ impl DisplayWithWorld for ScriptError {
162
154
fn display_with_world ( & self , world : crate :: bindings:: WorldGuard ) -> String {
163
155
if let Some ( script) = & self . 0 . script {
164
156
format ! (
165
- "error in script `{}`: {}.\n {}" ,
157
+ "error in script `{}`: {}.\n Context: {}" ,
166
158
script,
167
159
self . 0 . reason. display_with_world( world) ,
168
160
self . 0 . context
169
161
)
170
162
} else {
171
163
format ! (
172
- "error: {}.\n {}" ,
164
+ "error: {}.\n Context: {}" ,
173
165
self . 0 . reason. display_with_world( world) ,
174
166
self . 0 . context
175
167
)
@@ -211,72 +203,93 @@ impl From<InteropError> for ScriptError {
211
203
}
212
204
213
205
impl InteropError {
206
+ /// Thrown if a callback requires world access, but is unable to do so due
207
+ /// to the world not being reachable at all via any mechanism.
214
208
pub fn missing_world ( ) -> Self {
215
209
Self ( Arc :: new ( InteropErrorInner :: MissingWorld ) )
216
210
}
217
211
212
+ /// Thrown if a callback requires world access, but is unable to do so due
213
+ /// to the world being dropped. I.e. Symptom of a script trying to persist a world reference somewhere.
218
214
pub fn stale_world_access ( ) -> Self {
219
215
Self ( Arc :: new ( InteropErrorInner :: StaleWorldAccess ) )
220
216
}
221
217
218
+ /// Thrown if a base type is not registered with the reflection system
219
+ /// and therefore the reference cannot be dereferenced
222
220
pub fn unregistered_base ( base : ReflectBaseType ) -> Self {
223
221
Self ( Arc :: new ( InteropErrorInner :: UnregisteredBase { base } ) )
224
222
}
225
223
224
+ /// Thrown if a base type is not registered with the reflection system
225
+ /// with the specific type data.
226
226
pub fn missing_type_data ( type_id : TypeId , type_data : String ) -> Self {
227
227
Self ( Arc :: new ( InteropErrorInner :: MissingTypeData {
228
228
type_id,
229
229
type_data,
230
230
} ) )
231
231
}
232
232
233
+ /// Thrown if a type cannot be converted from reflect, this can happen if the type was unable to
234
+ /// re-construct itself from a dynamic value.
233
235
pub fn failed_from_reflect ( type_id : Option < TypeId > , reason : String ) -> Self {
234
236
Self ( Arc :: new ( InteropErrorInner :: FailedFromReflect {
235
237
type_id,
236
238
reason,
237
239
} ) )
238
240
}
239
241
242
+ /// Thrown if access to the given reflection base is required but cannot be claimed.
243
+ /// This is likely due to some other script already claiming access to the base.
240
244
pub fn cannot_claim_access ( base : ReflectBaseType ) -> Self {
241
245
Self ( Arc :: new ( InteropErrorInner :: CannotClaimAccess { base } ) )
242
246
}
243
247
248
+ /// Thrown if a conversion into the given type is impossible.
249
+ /// Should be thrown with context on the other type if possible.
244
250
pub fn impossible_conversion ( into : TypeId ) -> Self {
245
251
Self ( Arc :: new ( InteropErrorInner :: ImpossibleConversion { into } ) )
246
252
}
247
253
254
+ /// Thrown if a value was expected to be of one type but was of another
248
255
pub fn type_mismatch ( expected : TypeId , got : Option < TypeId > ) -> Self {
249
256
Self ( Arc :: new ( InteropErrorInner :: TypeMismatch { expected, got } ) )
250
257
}
251
258
259
+ /// Identical to [`InteropError::type_mismatch`] but for more abstract types
252
260
pub fn string_type_mismatch ( expected : String , got : Option < TypeId > ) -> Self {
253
261
Self ( Arc :: new ( InteropErrorInner :: StringTypeMismatch {
254
262
expected,
255
263
got,
256
264
} ) )
257
265
}
258
266
267
+ /// Thrown if a [`ScriptValue`] could not be converted to the expected type
259
268
pub fn value_mismatch ( expected : TypeId , got : ScriptValue ) -> Self {
260
269
Self ( Arc :: new ( InteropErrorInner :: ValueMismatch { expected, got } ) )
261
270
}
262
271
272
+ /// Thrown if a downcast from a reflect reference to a specific type failed
263
273
pub fn could_not_downcast ( from : ReflectReference , to : TypeId ) -> Self {
264
274
Self ( Arc :: new ( InteropErrorInner :: CouldNotDowncast { from, to } ) )
265
275
}
266
276
277
+ /// Thrown if a garbage collected allocation was attempted to be accessed
267
278
pub fn garbage_collected_allocation ( reference : ReflectReference ) -> Self {
268
279
Self ( Arc :: new ( InteropErrorInner :: GarbageCollectedAllocation {
269
280
reference,
270
281
} ) )
271
282
}
272
283
284
+ /// Thrown if a reflection path is invalid
273
285
pub fn reflection_path_error ( error : String , reference : Option < ReflectReference > ) -> Self {
274
286
Self ( Arc :: new ( InteropErrorInner :: ReflectionPathError {
275
287
error,
276
288
reference,
277
289
} ) )
278
290
}
279
291
292
+ /// Thrown if an operation is not supported on the given base type, optionally with a value argument that was used to carry it out
280
293
pub fn unsupported_operation (
281
294
base : Option < TypeId > ,
282
295
value : Option < Box < dyn PartialReflect > > ,
@@ -289,20 +302,24 @@ impl InteropError {
289
302
} ) )
290
303
}
291
304
305
+ /// Thrown if an invalid index operation was attempted on a value
292
306
pub fn invalid_index ( value : ScriptValue , reason : String ) -> Self {
293
307
Self ( Arc :: new ( InteropErrorInner :: InvalidIndex { value, reason } ) )
294
308
}
295
309
310
+ /// Thrown if an entity was missing or invalid
296
311
pub fn missing_entity ( entity : Entity ) -> Self {
297
312
Self ( Arc :: new ( InteropErrorInner :: MissingEntity { entity } ) )
298
313
}
299
314
315
+ /// Thrown if a component was invalid
300
316
pub fn invalid_component ( component_id : ComponentId ) -> Self {
301
317
Self ( Arc :: new ( InteropErrorInner :: InvalidComponent {
302
318
component_id,
303
319
} ) )
304
320
}
305
321
322
+ /// Thrown when an error happens in a function call. The inner error provides details on the error.
306
323
pub fn function_interop_error (
307
324
function_info : & FunctionInfo ,
308
325
argument_info : Option < & ArgInfo > ,
@@ -327,6 +344,9 @@ impl InteropError {
327
344
} ) )
328
345
}
329
346
347
+ /// Thrown when the error happens after a function call, and an error is thrown by bevy.
348
+ ///
349
+ /// I.e. mismatch in args, or invalid number of arguments
330
350
pub fn function_call_error ( inner : FunctionError ) -> Self {
331
351
Self ( Arc :: new ( InteropErrorInner :: FunctionCallError { inner } ) )
332
352
}
0 commit comments