Add error handler to prevent crashes and make investagation easier

This commit is contained in:
dazedanon 2025-12-18 19:22:40 -06:00
parent 75bb676741
commit 79ad2e5f2a
4 changed files with 494 additions and 407 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,12 @@
// Generated by RPG Maker.
// Do not edit this file directly.
var $plugins = [
{
name: "ErrorHandler",
status: true,
description: "Shows detailed error messages for script calls instead of crashing",
parameters: {},
},
{
name: "PluginCommonBase",
status: true,

View file

@ -0,0 +1,40 @@
// ==================================================
// ERROR HANDLER PATCH FOR RPG MAKER MZ
// Place this in js/plugins and enable it
// ==================================================
/*:
* @target MZ
* @plugindesc Shows detailed error messages for script calls instead of crashing
* @author Debug Helper
*
* @help This plugin catches script execution errors and displays them
* in the console with the actual code that failed.
*/
(() => {
const _Game_Interpreter_command355 = Game_Interpreter.prototype.command355;
Game_Interpreter.prototype.command355 = function() {
const script = this.currentCommand().parameters[0];
try {
return _Game_Interpreter_command355.call(this);
} catch (e) {
console.error('==========================================');
console.error('SCRIPT EXECUTION ERROR CAUGHT:');
console.error('==========================================');
console.error('Error:', e.message);
console.error('Script that failed:');
console.error(script);
console.error('==========================================');
// Show error in battle log if available
if (BattleManager._logWindow) {
BattleManager._logWindow.addText('\\c[18][SCRIPT ERROR: ' + e.message + ']');
}
// Continue execution instead of crashing
return true;
}
};
})();

41
validate_scripts.js Normal file
View file

@ -0,0 +1,41 @@
// Script to validate all code 355 JavaScript commands in CommonEvents.json
const fs = require('fs');
console.log('Loading CommonEvents.json...');
const data = JSON.parse(fs.readFileSync('./data/CommonEvents.json', 'utf8'));
let errorCount = 0;
let totalScripts = 0;
console.log('Validating script calls...\n');
data.forEach((event, eventIndex) => {
if (!event || !event.list) return;
event.list.forEach((command, cmdIndex) => {
if (command.code === 355 && command.parameters && command.parameters[0]) {
totalScripts++;
const script = command.parameters[0];
try {
// Try to parse the script as a Function to check syntax
new Function(script);
} catch (e) {
errorCount++;
console.log(`ERROR in Event ${event.id} "${event.name}" (Command index ${cmdIndex}):`);
console.log(`Script: ${script.substring(0, 100)}...`);
console.log(`Error: ${e.message}\n`);
}
}
});
});
console.log(`\n=== VALIDATION COMPLETE ===`);
console.log(`Total scripts checked: ${totalScripts}`);
console.log(`Errors found: ${errorCount}`);
if (errorCount === 0) {
console.log('\nAll scripts are syntactically valid!');
} else {
console.log('\nPlease fix the errors above.');
}