@@ -119,14 +119,6 @@ impl ScriptError {
119119 } ) )
120120 }
121121
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-
130122 pub fn with_script < S : ToString > ( self , script : S ) -> Self {
131123 Self ( Arc :: new ( ScriptErrorInner {
132124 script : Some ( script. to_string ( ) ) ,
@@ -135,10 +127,10 @@ impl ScriptError {
135127 } ) )
136128 }
137129
138- pub fn with_appended_context < S : ToString > ( self , context : S ) -> Self {
130+ pub fn with_context < S : ToString > ( self , context : S ) -> Self {
139131 Self ( Arc :: new ( ScriptErrorInner {
140132 script : self . 0 . script . clone ( ) ,
141- context : format ! ( "{}. {}" , self . 0 . context, context. to_string( ) ) ,
133+ context : format ! ( "{}\n {}" , self . 0 . context, context. to_string( ) ) ,
142134 reason : self . 0 . reason . clone ( ) ,
143135 } ) )
144136 }
@@ -149,11 +141,11 @@ impl std::fmt::Display for ScriptError {
149141 if let Some ( script) = & self . 0 . script {
150142 write ! (
151143 f,
152- "error in script `{}`: {}.\n {}" ,
144+ "error in script `{}`: {}.\n Context: {}" ,
153145 script, self . 0 . reason, self . 0 . context
154146 )
155147 } else {
156- write ! ( f, "error: {}.\n {}" , self . 0 . reason, self . 0 . context)
148+ write ! ( f, "error: {}.\n Context: {}" , self . 0 . reason, self . 0 . context)
157149 }
158150 }
159151}
@@ -162,14 +154,14 @@ impl DisplayWithWorld for ScriptError {
162154 fn display_with_world ( & self , world : crate :: bindings:: WorldGuard ) -> String {
163155 if let Some ( script) = & self . 0 . script {
164156 format ! (
165- "error in script `{}`: {}.\n {}" ,
157+ "error in script `{}`: {}.\n Context: {}" ,
166158 script,
167159 self . 0 . reason. display_with_world( world) ,
168160 self . 0 . context
169161 )
170162 } else {
171163 format ! (
172- "error: {}.\n {}" ,
164+ "error: {}.\n Context: {}" ,
173165 self . 0 . reason. display_with_world( world) ,
174166 self . 0 . context
175167 )
@@ -211,72 +203,93 @@ impl From<InteropError> for ScriptError {
211203}
212204
213205impl 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.
214208 pub fn missing_world ( ) -> Self {
215209 Self ( Arc :: new ( InteropErrorInner :: MissingWorld ) )
216210 }
217211
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.
218214 pub fn stale_world_access ( ) -> Self {
219215 Self ( Arc :: new ( InteropErrorInner :: StaleWorldAccess ) )
220216 }
221217
218+ /// Thrown if a base type is not registered with the reflection system
219+ /// and therefore the reference cannot be dereferenced
222220 pub fn unregistered_base ( base : ReflectBaseType ) -> Self {
223221 Self ( Arc :: new ( InteropErrorInner :: UnregisteredBase { base } ) )
224222 }
225223
224+ /// Thrown if a base type is not registered with the reflection system
225+ /// with the specific type data.
226226 pub fn missing_type_data ( type_id : TypeId , type_data : String ) -> Self {
227227 Self ( Arc :: new ( InteropErrorInner :: MissingTypeData {
228228 type_id,
229229 type_data,
230230 } ) )
231231 }
232232
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.
233235 pub fn failed_from_reflect ( type_id : Option < TypeId > , reason : String ) -> Self {
234236 Self ( Arc :: new ( InteropErrorInner :: FailedFromReflect {
235237 type_id,
236238 reason,
237239 } ) )
238240 }
239241
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.
240244 pub fn cannot_claim_access ( base : ReflectBaseType ) -> Self {
241245 Self ( Arc :: new ( InteropErrorInner :: CannotClaimAccess { base } ) )
242246 }
243247
248+ /// Thrown if a conversion into the given type is impossible.
249+ /// Should be thrown with context on the other type if possible.
244250 pub fn impossible_conversion ( into : TypeId ) -> Self {
245251 Self ( Arc :: new ( InteropErrorInner :: ImpossibleConversion { into } ) )
246252 }
247253
254+ /// Thrown if a value was expected to be of one type but was of another
248255 pub fn type_mismatch ( expected : TypeId , got : Option < TypeId > ) -> Self {
249256 Self ( Arc :: new ( InteropErrorInner :: TypeMismatch { expected, got } ) )
250257 }
251258
259+ /// Identical to [`InteropError::type_mismatch`] but for more abstract types
252260 pub fn string_type_mismatch ( expected : String , got : Option < TypeId > ) -> Self {
253261 Self ( Arc :: new ( InteropErrorInner :: StringTypeMismatch {
254262 expected,
255263 got,
256264 } ) )
257265 }
258266
267+ /// Thrown if a [`ScriptValue`] could not be converted to the expected type
259268 pub fn value_mismatch ( expected : TypeId , got : ScriptValue ) -> Self {
260269 Self ( Arc :: new ( InteropErrorInner :: ValueMismatch { expected, got } ) )
261270 }
262271
272+ /// Thrown if a downcast from a reflect reference to a specific type failed
263273 pub fn could_not_downcast ( from : ReflectReference , to : TypeId ) -> Self {
264274 Self ( Arc :: new ( InteropErrorInner :: CouldNotDowncast { from, to } ) )
265275 }
266276
277+ /// Thrown if a garbage collected allocation was attempted to be accessed
267278 pub fn garbage_collected_allocation ( reference : ReflectReference ) -> Self {
268279 Self ( Arc :: new ( InteropErrorInner :: GarbageCollectedAllocation {
269280 reference,
270281 } ) )
271282 }
272283
284+ /// Thrown if a reflection path is invalid
273285 pub fn reflection_path_error ( error : String , reference : Option < ReflectReference > ) -> Self {
274286 Self ( Arc :: new ( InteropErrorInner :: ReflectionPathError {
275287 error,
276288 reference,
277289 } ) )
278290 }
279291
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
280293 pub fn unsupported_operation (
281294 base : Option < TypeId > ,
282295 value : Option < Box < dyn PartialReflect > > ,
@@ -289,20 +302,24 @@ impl InteropError {
289302 } ) )
290303 }
291304
305+ /// Thrown if an invalid index operation was attempted on a value
292306 pub fn invalid_index ( value : ScriptValue , reason : String ) -> Self {
293307 Self ( Arc :: new ( InteropErrorInner :: InvalidIndex { value, reason } ) )
294308 }
295309
310+ /// Thrown if an entity was missing or invalid
296311 pub fn missing_entity ( entity : Entity ) -> Self {
297312 Self ( Arc :: new ( InteropErrorInner :: MissingEntity { entity } ) )
298313 }
299314
315+ /// Thrown if a component was invalid
300316 pub fn invalid_component ( component_id : ComponentId ) -> Self {
301317 Self ( Arc :: new ( InteropErrorInner :: InvalidComponent {
302318 component_id,
303319 } ) )
304320 }
305321
322+ /// Thrown when an error happens in a function call. The inner error provides details on the error.
306323 pub fn function_interop_error (
307324 function_info : & FunctionInfo ,
308325 argument_info : Option < & ArgInfo > ,
@@ -327,6 +344,9 @@ impl InteropError {
327344 } ) )
328345 }
329346
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
330350 pub fn function_call_error ( inner : FunctionError ) -> Self {
331351 Self ( Arc :: new ( InteropErrorInner :: FunctionCallError { inner } ) )
332352 }
0 commit comments