Crash mod
Example apps / crash-mod / v0.1.0
Node mod
Four ways for a mod to fail: a thrown error, an endless loop, process.exit and a killed process. Other mods keep running.
The preview runs the mod in a Web Worker, so the endless loop cannot freeze this page, and it restarts it the way REDnode does.
// Crash mod: four ways for a mod to fail. Each button tests what REDnode
// contains. Use it with the launcher's Shared process switch to compare.
import { ui } from 'rednode';
ui.window({
title: 'Crash mod',
anchor: 'left',
x: 40,
y: 0,
width: 340,
height: 330,
children: [
ui.text('Each button breaks this mod in a different way. Other mods should keep running.', { tone: 'dim' }),
ui.button('Throw an error', () => {
throw new Error('Crash mod threw this on purpose');
}, { variant: 'danger' }),
ui.button('Hang forever', () => {
console.log('Hanging now: an endless loop');
for (;;) {
// never returns
}
}, { variant: 'danger' }),
ui.button('Exit', () => {
console.log('Calling process.exit(3)');
process.exit(3);
}, { variant: 'danger' }),
ui.button('Kill the process', () => {
// Ends the whole mod process at once, the way a crash in native code would.
console.log('Killing the mod process');
process.kill(process.pid, 'SIGKILL');
}, { variant: 'danger' }),
],
});
console.log('Crash mod ready');
REDnode runs JavaScript. The rednode package also has TypeScript types, so an editor checks these calls; compile TypeScript to .mjs first.
{
"id": "crash-mod",
"name": "Crash mod",
"version": "0.1.0",
"author": "Edgemodders",
"description": "Breaks on purpose, to test that one bad mod cannot take down the others. Off until you turn it on.",
"main": "mod.mjs",
"open": false
}
The manifest names the package and says how REDnode runs it. Its fields are in Overlay apps.
How it works
Each Node mod runs on its own worker thread. A thrown error or an exit stops only that mod, and REDnode restarts it, at most three times a minute.
An endless loop never answers REDnode's pings: after ten seconds the mod shows as not responding, and the player can restart it.
What it uses
crash handling restart not responding
Try this
- Press Throw an error, then watch the Mod log and the status: the mod restarts.
- Press Hang forever and wait ten seconds, then press Restart.
Use it
Copy the files into red4ext/plugins/REDnode/apps/crash-mod/ in the game folder, or start your own package from them: change id and name in the manifest first. The whole folder is on GitHub.