Skip to content

Commit 26f9869

Browse files
shanecelismakspll
andauthored
Send ScriptErrorEvent when load fails. (#125)
* feature: Send ScriptErrorEvent when load fails. * formatting * clippy overrides * properly fix clippy errors --------- Co-authored-by: makspll <makspl17@gmail.com>
1 parent c2c3bda commit 26f9869

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

clippy.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
type-complexity-threshold=1000
1+
type-complexity-threshold = 1000
2+
too-many-arguments-threshold = 999

crates/bevy_mod_scripting_core/src/hosts.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::{
1212
error::ScriptError,
1313
event::{ScriptEvent, ScriptLoaded},
1414
world::WorldPointer,
15+
ScriptErrorEvent,
1516
};
1617

1718
/// Describes the target set of scripts this event should
@@ -358,6 +359,7 @@ impl<T: Asset> Script<T> {
358359
providers: &mut APIProviders<H>,
359360
contexts: &mut ScriptContexts<H::ScriptContext>,
360361
event_writer: &mut EventWriter<ScriptLoaded>,
362+
error_writer: &mut EventWriter<ScriptErrorEvent>,
361363
) {
362364
debug!("reloading script {}", script.id);
363365

@@ -374,6 +376,7 @@ impl<T: Asset> Script<T> {
374376
providers,
375377
contexts,
376378
event_writer,
379+
error_writer,
377380
);
378381
} else {
379382
// remove old context
@@ -392,6 +395,7 @@ impl<T: Asset> Script<T> {
392395
providers: &mut APIProviders<H>,
393396
contexts: &mut ScriptContexts<H::ScriptContext>,
394397
event_writer: &mut EventWriter<ScriptLoaded>,
398+
error_writer: &mut EventWriter<ScriptErrorEvent>,
395399
) {
396400
let fd = ScriptData {
397401
sid: new_script.id(),
@@ -424,6 +428,7 @@ impl<T: Asset> Script<T> {
424428
// this script will now never execute, unless manually reloaded
425429
// but contexts are left in a valid state
426430
contexts.insert_context(fd, None);
431+
error_writer.send(ScriptErrorEvent { error: e });
427432
}
428433
}
429434
}

crates/bevy_mod_scripting_core/src/systems.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
3333
script_assets: Res<Assets<H::ScriptAsset>>,
3434
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
3535
mut event_writer: EventWriter<ScriptLoaded>,
36+
mut error_writer: EventWriter<ScriptErrorEvent>,
3637
) {
3738
debug!("Handling addition/modification of scripts");
3839

@@ -47,6 +48,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
4748
&mut providers,
4849
&mut contexts,
4950
&mut event_writer,
51+
&mut error_writer,
5052
)
5153
})
5254
} else {
@@ -84,6 +86,7 @@ pub fn script_add_synchronizer<H: ScriptHost + 'static>(
8486
&mut providers,
8587
&mut contexts,
8688
&mut event_writer,
89+
&mut error_writer,
8790
)
8891
}
8992
}
@@ -120,6 +123,7 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
120123
mut providers: ResMut<APIProviders<H>>,
121124
mut contexts: ResMut<ScriptContexts<H::ScriptContext>>,
122125
mut event_writer: EventWriter<ScriptLoaded>,
126+
mut error_writer: EventWriter<ScriptErrorEvent>,
123127
) {
124128
for e in events.read() {
125129
let (handle, created) = match e {
@@ -147,6 +151,7 @@ pub fn script_hot_reload_handler<H: ScriptHost>(
147151
&mut providers,
148152
&mut contexts,
149153
&mut event_writer,
154+
&mut error_writer,
150155
);
151156
}
152157
}

0 commit comments

Comments
 (0)