mirror of
https://github.com/tobspr/shapez.io.git
synced 2025-12-09 16:21:51 +00:00
Simplify pointless try/catch wrappers
Remove try/catch wrappers that just log and/or rethrow the error, use the cause chain for rethrows with descriptions. Remove inner try/catch for mod loading to make errors more obvious.
This commit is contained in:
parent
515c07c067
commit
ca5dd9b3e5
@ -52,7 +52,7 @@ export class Application {
|
||||
try {
|
||||
await MODS.initMods();
|
||||
} catch (ex) {
|
||||
alert("Failed to load mods (launch with --dev for more info): \n\n" + ex);
|
||||
throw new Error("Failed to initialize mods", { cause: ex });
|
||||
}
|
||||
|
||||
this.unloaded = false;
|
||||
|
||||
@ -52,11 +52,7 @@ export class AnimationFrame {
|
||||
dt = resetDtMs;
|
||||
}
|
||||
|
||||
try {
|
||||
this.frameEmitted.dispatch(dt);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
}
|
||||
this.frameEmitted.dispatch(dt);
|
||||
this.lastTime = time;
|
||||
window.requestAnimationFrame(this.boundMethod);
|
||||
}
|
||||
|
||||
@ -95,12 +95,8 @@ export class StateManager {
|
||||
const dialogParent = document.createElement("div");
|
||||
dialogParent.classList.add("modalDialogParent");
|
||||
document.body.appendChild(dialogParent);
|
||||
try {
|
||||
this.currentState.internalEnterCallback(payload);
|
||||
} catch (ex) {
|
||||
console.error(ex);
|
||||
throw ex;
|
||||
}
|
||||
|
||||
this.currentState.internalEnterCallback(payload);
|
||||
|
||||
this.app.sound.playThemeMusic(this.currentState.getThemeMusic());
|
||||
|
||||
|
||||
@ -275,7 +275,7 @@ function generateUpgrades() {
|
||||
try {
|
||||
ShapeDefinition.fromShortKey(shape);
|
||||
} catch (ex) {
|
||||
throw new Error("Invalid upgrade goal: '" + ex + "' for shape" + shape);
|
||||
throw new Error("Invalid upgrade goal for shape " + shape, { cause: ex });
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -305,7 +305,7 @@ export function generateLevelDefinitions() {
|
||||
try {
|
||||
ShapeDefinition.fromShortKey(shape);
|
||||
} catch (ex) {
|
||||
throw new Error("Invalid tutorial goal: '" + ex + "' for shape" + shape);
|
||||
throw new Error("Invalid tutorial goal for shape " + shape, { cause: ex });
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -2,7 +2,6 @@ import { GLOBAL_APP } from "@/core/globals";
|
||||
import { SavegameStoredMods } from "@/savegame/savegame_typedefs";
|
||||
import { createLogger } from "../core/logging";
|
||||
import { DisabledMod } from "./disabled_mod";
|
||||
import { ErroredMod } from "./errored_mod";
|
||||
import { Mod, ModConstructor } from "./mod";
|
||||
import { ModInfo, ModMetadata, ModQueueEntry } from "./mod_metadata";
|
||||
import { MOD_SIGNALS } from "./mod_signals";
|
||||
@ -84,22 +83,16 @@ export class ModLoader {
|
||||
queue.map(async e => ({ entry: e, mod: await this.loadMod(e) }))
|
||||
);
|
||||
|
||||
// Initialize all mods sequentially and collect errors
|
||||
// Initialize all mods sequentially
|
||||
// TODO: Also collect early errors from the main process
|
||||
for (const { entry, mod } of loadedMods) {
|
||||
try {
|
||||
await mod.init();
|
||||
} catch (err) {
|
||||
if (err instanceof Error) {
|
||||
mod.errors.push(err);
|
||||
}
|
||||
}
|
||||
|
||||
this.mods.set(mod.id, {
|
||||
source: entry.source,
|
||||
file: entry.file,
|
||||
mod,
|
||||
});
|
||||
|
||||
await mod.init();
|
||||
}
|
||||
}
|
||||
|
||||
@ -139,13 +132,7 @@ export class ModLoader {
|
||||
return new DisabledMod(entry.metadata, this.app, this);
|
||||
}
|
||||
|
||||
try {
|
||||
return await this.createModInstance(entry.metadata);
|
||||
} catch (err) {
|
||||
const mod = new ErroredMod(entry.metadata, this.app, this);
|
||||
mod.errors.push(err instanceof Error ? err : new Error(err.toString()));
|
||||
return mod;
|
||||
}
|
||||
return await this.createModInstance(entry.metadata);
|
||||
}
|
||||
|
||||
private async createModInstance(metadata: ModMetadata): Promise<Mod> {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user