Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

fix(export): a mini-game that fails to start says why

esengine51daf7994cac
diff --git a/pipeline/src/export/miniGameExportProfile.ts b/pipeline/src/export/miniGameExportProfile.ts
index e685b18cf..cb0c70f51 100644
--- a/pipeline/src/export/miniGameExportProfile.ts
+++ b/pipeline/src/export/miniGameExportProfile.ts
@@ -108,7 +108,11 @@ const sideModuleFactories = {
${requires}
};
const bundle = require('./game-bundle.js');
-bundle.boot(engineFactory, sideModuleFactories);`;
+// A boot that fails rejects; a host without onUnhandledRejection drops that
+// silently, which leaves a device on the loading screen with nothing in the log.
+Promise.resolve(bundle.boot(engineFactory, sideModuleFactories)).catch(function (e) {
+ console.error('[estella] the game did not start: ' + ((e && (e.stack || e.message)) || e));
+});`;
if (!ctx.engineSubpackage) {
// Before the bundle is REQUIRED: the runtime's own indicator cannot
// cover a wait that ends when the runtime arrives. Guarded, like every
diff --git a/sdk/src/runtime/miniGameRuntime.ts b/sdk/src/runtime/miniGameRuntime.ts
index cd7354b81..549f84076 100644
--- a/sdk/src/runtime/miniGameRuntime.ts
+++ b/sdk/src/runtime/miniGameRuntime.ts
@@ -44,7 +44,7 @@ function createWasmInstantiator(wasmPath: string, tag: string, onError?: (e: unk
platformInstantiateWasm(wasmPath, imports).then((result) => {
successCallback(result.instance, result.module);
}).catch((e) => {
- log.error(tag, 'WASM instantiation failed', e);
+ log.error(tag, `WASM instantiation failed: ${describeError(e)}`);
// emscripten's instantiateWasm has no failure channel: on a failed
// async instantiation successCallback is never called and the factory
// promise hangs forever. Surface the error so the caller can reject.
@@ -54,6 +54,19 @@ function createWasmInstantiator(wasmPath: string, tag: string, onError?: (e: unk
};
}
+/** A mini-game console prints a thrown object as `[object Object]`, so the one
+ * line a device gives you says nothing unless it is made into text here. */
+function describeError(e: unknown): string {
+ if (e instanceof Error) return `${e.name}: ${e.message}`;
+ if (e && typeof e === 'object') {
+ const o = e as { message?: unknown; errMsg?: unknown };
+ if (typeof o.message === 'string') return o.message;
+ if (typeof o.errMsg === 'string') return o.errMsg;
+ try { return JSON.stringify(e); } catch { /* fall through */ }
+ }
+ return String(e);
+}
+
// Wraps an emscripten module factory so an async instantiateWasm failure rejects
// the returned promise instead of hanging the module load indefinitely.
function instantiateModule<T>(