- Joined
- Oct 25, 2015
- Messages
- 52
- Reaction score
- 39
- First Language
- English
- Primarily Uses
- N/A
WARNING: This plugin is deprecated as of RPG Maker MV 1.3.1. Please do not use it.
Since this plugin has never been popular or had an official release, I have no plans to keep it up-to-date.
The Error Handler plugin (formerly known as AntiCrash) provides options for responding to non-critical runtime errors.
I started this plugin because I am porting a heavily scripted game from VX Ace to MV, and it's a lot of work! I wanted to playtest and develop the game without worrying about crashes due to missing non-essential assets. Instead of always crashing for such errors, Error Handler lets the developer choose one or more of the following actions to take in the event of an error:
In any non-crashing case, the Error Handler plugin aids graceful recovery so that play can continue.
You can configure error handling independently for each error type. So far, the plugin handles the following error types:
This plugin is built to use alone or in any order relative to other plugins. There are no known conflicts, but conflict is possible with any plugin that fundamentally alters the way that audio or backgrounds are loaded or ready-checked.
During development, I recommend using this plugin with the Yanfly Core Engine plugin with Open Console set to true; the console gives detailed feedback on non-crashing image and audio load errors.
I consider this plugin safe to use as is, but is it useful enough to release? What other non-critical errors would you like to see crash-proofed?
The spoiler below contains the script so far. You are welcome to use it immediately (at your own risk!) for any kind of project, with no attribution required.
Since this plugin has never been popular or had an official release, I have no plans to keep it up-to-date.
The Error Handler plugin (formerly known as AntiCrash) provides options for responding to non-critical runtime errors.
I started this plugin because I am porting a heavily scripted game from VX Ace to MV, and it's a lot of work! I wanted to playtest and develop the game without worrying about crashes due to missing non-essential assets. Instead of always crashing for such errors, Error Handler lets the developer choose one or more of the following actions to take in the event of an error:
- Log the error to a file.
- Show a pop-up with the error.
- Crash the game.
In any non-crashing case, the Error Handler plugin aids graceful recovery so that play can continue.
You can configure error handling independently for each error type. So far, the plugin handles the following error types:
- Failure to load any audio file (BGM, BGS, ME, SE)
- Failure to load a specific battleback1 or battleback2 file. An empty bitmap will be loaded in its place.
This plugin is built to use alone or in any order relative to other plugins. There are no known conflicts, but conflict is possible with any plugin that fundamentally alters the way that audio or backgrounds are loaded or ready-checked.
During development, I recommend using this plugin with the Yanfly Core Engine plugin with Open Console set to true; the console gives detailed feedback on non-crashing image and audio load errors.
I consider this plugin safe to use as is, but is it useful enough to release? What other non-critical errors would you like to see crash-proofed?
The spoiler below contains the script so far. You are welcome to use it immediately (at your own risk!) for any kind of project, with no attribution required.
Spoiler
Code:
//=============================================================================// Error Handler// by McKathlin// MCK_ErrorHandler.js// Last Update: 2015.11.07//=============================================================================/*: * @plugindesc Provides options for handling non-critical errors. * @author McKathlin * * @param Log Path * @desc The path of the error log file, relative to the project root. * @default error_log.txt * * @param On Audio Error * @desc What do do when there's an audio error. * Pop-up, Log, and/or Crash. Leave blank to ignore this error. * @default Pop-up, Log * * @param On Battleback Error * @desc What to do when a battleback file won't load. * Pop-up, Log, and/or Crash. Leave blank to ignore this error. * @default Pop-up, Log * * @help This plugin does not provide plugin commands. * * The Error Handler plugin's purpose is to provide options for reporting * non-critical errors, without having to crash the game. * * There are no known conflicts with this plugin. * It is probably usable anywhere in the list. Near the end is recommended. * * Each parameter named after the pattern "On ______ Error" accepts any * combination of the following three values: Log, Pop-up, Crash * Log: Write the error message to the log file. * Pop-up: Display a pop-up window with the error message. * Crash: Show the error message on the game screen, and end play. * These terms are case-insensitive. Terms other than these are ignored. * If none of these three recognized parameter values are given, * then the Error Handler plugin will cause that error type to be ignored. * */var Imported = Imported || {};Imported.MCK_ErrorHandler = true;var McKathlin = McKathlin || {};McKathlin.ErrorHandlerPlugin = McKathlin.ErrorHandlerPlugin || {};//-----------------------------------------------------------------------------/** * The Logger class. * * @class McKathlin.Log * @constructor * @param {String} filePath The path where the log should be written. */ McKathlin.Log = function(filePath) { var fs = require('fs'); var root = window.location.pathname.replace(/(\/www|)\/[^\/]*$/, '/'); if (root.match(/^\/([A-Z]\:)/)) { root = root.slice(1); } rootPath = decodeURIComponent(root); var fullPath = rootPath + filePath; this._writeStream = fs.createWriteStream(fullPath, { flags: 'a' }); }; McKathlin.Log.prototype.write = function(str) { this._writeStream.write(str + "\r\n"); }; McKathlin.Log.prototype.close = function() { this._writeStream.end(); };//-----------------------------------------------------------------------------/** * The ErrorHandler class. * * @class McKathlin.ErrorHandler * @constructor * @param {String} paramString The plugin parameter value: Log, PopUp, and/or Crash. * @param {McKathlin.Log} log Where to log the errors. */McKathlin.ErrorHandler = function(paramString, log) { /** * @property logger * @type McKathlin.Log * @default null */ this.logger = log; /** * @property doesLog * @type Boolean * @default false */ this.doesLog = /log/i.test(paramString); /** * @property doesPopUp * @type Boolean * @default false */ this.doesPopUp = /pop[\- ]?up/i.test(paramString); /** * @property doesCrash * @type Boolean * @default false */ this.doesCrash = /crash/i.test(paramString);};McKathlin.ErrorHandler.prototype.handle = function(errorMessage) { if (this.doesLog && this.logger) { this.logger.write(errorMessage); } if (this.doesPopUp) { window.alert(errorMessage); } if (this.doesCrash) { throw new Error(errorMessage); }};//-----------------------------------------------------------------------------// Parameter and Tool InitMcKathlin.Parameters = PluginManager.parameters('MCK_ErrorHandler');McKathlin.Param = McKathlin.Param || {};McKathlin.Param.OnAudioError = String( McKathlin.Parameters['On Audio Error']);McKathlin.Param.OnBattlebackError = String( McKathlin.Parameters['On Battleback Error']);McKathlin.Param.LogPath = String(McKathlin.Parameters['Log Path'])McKathlin.ErrorLog = new McKathlin.Log(McKathlin.Param.LogPath);McKathlin.AudioErrorHandler = new McKathlin.ErrorHandler( McKathlin.Param.OnAudioError, McKathlin.ErrorLog);McKathlin.BattlebackErrorHandler = new McKathlin.ErrorHandler( McKathlin.Param.OnBattlebackError, McKathlin.ErrorLog);//-----------------------------------------------------------------------------// Audio Error ManagementAudioManager.checkWebAudioError = function(webAudio) { if (webAudio && webAudio.isError()) { McKathlin.AudioErrorHandler.handle('Failed to load audio: ' + webAudio.url); webAudio.clear(); }};//-----------------------------------------------------------------------------// Image Error Management// This replaces ImageManager.isReady() in rpg_managers.js// Instead of crashing if a bitmap has an error,// it calls a method to check for and handle bitmap errors.ImageManager.isReady = function() { for (var key in this._cache) { var bitmap = this._cache[key]; if (bitmap.isError()) { this.handleBitmapErrorAt(key); } if (!bitmap.isReady()) { return false; } } return true;};// New method to handle bitmap errorsImageManager.handleBitmapErrorAt = function(key) { var bitmap = this._cache[key]; if (bitmap.isError()) { if (/^img\/battlebacks[12]\//.test(bitmap.url)) { // This is a BattleBackground file. McKathlin.BattlebackErrorHandler.handle( 'Failed to load battle background: ' + bitmap.url); // We can see what's going on without any battle background, // so replace the error'd bitmap with a blank one. this._cache[key] = new Bitmap(); } else { // Other image types are not anti-crashed. // Make a crash similar to the default. throw new Error('Failed to load: ' + bitmap.url); } }};
Last edited by a moderator:

