Error Handler plugin. WARNING: Deprecated. Do not use.

McKathlin

Plugin dev, composer, artist
Veteran
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 res
ponding 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:

Iavra

Veteran
Veteran
Joined
Apr 9, 2015
Messages
1,797
Reaction score
863
First Language
German
Primarily Uses
While i personally think, that the game should crash if one or more files are missing (if it's a general problem, it probably wouldn't even have started in the first place), you should at least log an error or warning message and not ignore those errors.
 

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
I think you should make it crash while playtesting and leave the anti crash only for deployed games.
 

McKathlin

Plugin dev, composer, artist
Veteran
Joined
Oct 25, 2015
Messages
52
Reaction score
39
First Language
English
Primarily Uses
N/A
When I have a lot of work to do, I'd rather not be forced to fix non-essential audio and image errors before I try out my game's core features, but I may be in the minority.

If a warning log feature would make this useful to the general public, I'll be happy to add one.
 
Last edited by a moderator:

Hudell

Dog Lord
Veteran
Joined
Oct 2, 2014
Messages
3,545
Reaction score
3,715
First Language
Java's Crypt
Primarily Uses
RMMZ
I think you should at least show a popup message everytime a file is not found. Devs should be annoyed by their bugs so they don't forget to fix it.
 

McKathlin

Plugin dev, composer, artist
Veteran
Joined
Oct 25, 2015
Messages
52
Reaction score
39
First Language
English
Primarily Uses
N/A
I think you should at least show a popup message everytime a file is not found. Devs should be annoyed by their bugs so they don't forget to fix it.
Good idea, Hudell. For each type of error covered by AntiCrash, I think I'll let the developer configure the plugin to do one or a combination of these things: log, pop-up, or crash. Log and pop-up might be a good default setting for everything.
 

gRaViJa

Veteran
Veteran
Joined
Mar 16, 2012
Messages
882
Reaction score
398
First Language
Dutch
I think it can come inhandy to add before you share your game. If a single sound effect get's lost somehow, you don't end up with a broken game. I also don't recommend to use it while creating the game itself though. Thanks for the plugin, McKathlin
 

McKathlin

Plugin dev, composer, artist
Veteran
Joined
Oct 25, 2015
Messages
52
Reaction score
39
First Language
English
Primarily Uses
N/A
I think it can come inhandy to add before you share your game. If a single sound effect get's lost somehow, you don't end up with a broken game. I also don't recommend to use it while creating the game itself though. Thanks for the plugin, McKathlin
Thanks, Gravija.

I do use Anti-Crash during development because I'm working with a team. My most urgent goal is to free my teammates up to do their work. I handle the graphics, sound, and code; one teammate primarily builds maps and storyline events; and another balances battles, shops, treasure, and other gameplay elements. If their playtests crash immediately because I haven't converted our sound effects to OGG yet, then they're both stuck waiting for me.  I have lots to do already, and I like to get mechanics ready first and aesthetics afterwards.

Most RPG Maker developers' workflow probably differs a lot from ours.

*edited for brevity and clarity
 
Last edited by a moderator:

McKathlin

Plugin dev, composer, artist
Veteran
Joined
Oct 25, 2015
Messages
52
Reaction score
39
First Language
English
Primarily Uses
N/A
I've taken Iavra's and Hudell's suggestions to heart and updated this plugin (now called Error Handler) to let the developer choose whether to log, show a pop-up, or crash for each error type covered. If you would like to see these error handling options available for more types of errors, please let me know what error types you'd like to see covered. Thanks, everyone!
 

McKathlin

Plugin dev, composer, artist
Veteran
Joined
Oct 25, 2015
Messages
52
Reaction score
39
First Language
English
Primarily Uses
N/A
Kath_ErrorHandler.js is now deprecated. If you've updated your RPG Maker MV core engine to version 1.3.1 or any later version, please don't use Kath_ErrorHandler.js. This is an unpopular plugin that has never seen official release, so I have no plans to bring it up-to-date. But if someone really needs an update to the Error Handler, speak up. I'll do my best to help you.
 
Last edited by a moderator:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:

Forum statistics

Threads
105,854
Messages
1,017,004
Members
137,562
Latest member
tamedeathman
Top