Skip to content

Commit 237c9fb

Browse files
committed
fix: handle null makeRenderImage on headless Linux, catch microtask errors
1 parent bafe36a commit 237c9fb

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

scripts/rive-extract-schema.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,18 @@ console.log = (...args: unknown[]) =>
2929
console.warn = (...args: unknown[]) =>
3030
process.stderr.write(args.join(' ') + '\n');
3131

32+
// Catch errors from microtasks/unhandled rejections that would otherwise cause
33+
// a silent exit with code 0 on some Bun versions (e.g. when img.la() throws in
34+
// a queueMicrotask callback because WebGL is unavailable on Linux CI).
35+
process.on('uncaughtException', (err) => {
36+
process.stderr.write(`uncaughtException: ${err.stack ?? err.message}\n`);
37+
process.exit(1);
38+
});
39+
process.on('unhandledRejection', (reason) => {
40+
process.stderr.write(`unhandledRejection: ${reason}\n`);
41+
process.exit(1);
42+
});
43+
3244
if (!input) {
3345
process.stderr.write('Usage: bun rive-extract-schema.ts <path-or-url>\n');
3446
process.exit(1);
@@ -50,12 +62,13 @@ async function main() {
5062

5163
// Stub image loading: call la() (the "loaded" callback) immediately so
5264
// runtime.load() resolves without waiting for CDN asset fetches.
65+
// Guard against null return when WebGL is unavailable (headless Linux).
5366
const origMRI = (runtime.renderFactory as any).makeRenderImage.bind(
5467
runtime.renderFactory
5568
);
5669
(runtime.renderFactory as any).makeRenderImage = function () {
5770
const img = origMRI();
58-
queueMicrotask(() => img.la());
71+
if (img) queueMicrotask(() => img.la?.());
5972
return img;
6073
};
6174

0 commit comments

Comments
 (0)