Skip to content

Commit 7bc9bd5

Browse files
committed
Revert "Revert "Show where the error is caused and let turn on/off showing detail""
This reverts commit a37cdfb.
1 parent 20f6db1 commit 7bc9bd5

File tree

12 files changed

+187
-27
lines changed

12 files changed

+187
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ game/**/*
5555
todo.md
5656
corescript/**/*
5757
corescript.zip
58+
package-lock.json

js/rpg_core/Graphics.js

Lines changed: 79 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,27 +420,32 @@ Graphics.printError = function(name, message) {
420420
this._errorPrinter.style.msUserSelect = 'text';
421421
this._errorPrinter.style.mozUserSelect = 'text';
422422
this._errorPrinter.oncontextmenu = null; // enable context menu
423-
this._makeErrorMessage();
423+
if (this._errorMessage) {
424+
this._makeErrorMessage();
425+
}
424426
}
425427
this._applyCanvasFilter();
426428
this._clearUpperCanvas();
427429
};
428430

429431
/**
430-
* Shows the stacktrace of error.
432+
* Shows the detail of error.
431433
*
432434
* @static
433-
* @method printStackTrace
435+
* @method printErrorDetail
434436
*/
435-
Graphics.printStackTrace = function(stack) {
436-
if (this._errorPrinter) {
437-
stack = (stack || '')
437+
Graphics.printErrorDetail = function(error) {
438+
if (this._errorPrinter && this._showErrorDetail) {
439+
var eventInfo = this._formatEventInfo(error);
440+
var eventCommandInfo = this._formatEventCommandInfo(error);
441+
var info = eventCommandInfo ? eventInfo + ", " + eventCommandInfo : eventInfo;
442+
var stack = (error.stack || '')
438443
.replace(/file:.*js\//g, '')
439444
.replace(/http:.*js\//g, '')
440445
.replace(/https:.*js\//g, '')
441446
.replace(/chrome-extension:.*js\//g, '')
442447
.replace(/\n/g, '<br>');
443-
this._makeStackTrace(decodeURIComponent(stack));
448+
this._makeErrorDetail(info, decodeURIComponent(stack));
444449
}
445450
};
446451

@@ -454,6 +459,16 @@ Graphics.setErrorMessage = function(message) {
454459
this._errorMessage = message;
455460
};
456461

462+
/**
463+
* Sets whether shows the detail of error.
464+
*
465+
* @static
466+
* @method setShowErrorDetail
467+
*/
468+
Graphics.setShowErrorDetail = function(showErrorDetail) {
469+
this._showErrorDetail = showErrorDetail;
470+
};
471+
457472
/**
458473
* Shows the FPSMeter element.
459474
*
@@ -877,7 +892,13 @@ Graphics._createErrorPrinter = function() {
877892
*/
878893
Graphics._updateErrorPrinter = function() {
879894
this._errorPrinter.width = this._width * 0.9;
880-
this._errorPrinter.height = this._errorShowed ? this._height * 0.9 : 40;
895+
if (this._errorShowed && this._showErrorDetail) {
896+
this._errorPrinter.height = this._height * 0.9;
897+
} else if (this._errorShowed && this._errorMessage) {
898+
this._errorPrinter.height = 100;
899+
} else {
900+
this._errorPrinter.height = 40;
901+
}
881902
this._errorPrinter.style.textAlign = 'center';
882903
this._errorPrinter.style.textShadow = '1px 1px 3px #000';
883904
this._errorPrinter.style.fontSize = '20px';
@@ -896,23 +917,66 @@ Graphics._makeErrorMessage = function() {
896917
style.color = 'white';
897918
style.textAlign = 'left';
898919
style.fontSize = '18px';
899-
mainMessage.innerHTML = '<hr>' + (this._errorMessage || '');
920+
mainMessage.innerHTML = '<hr>' + this._errorMessage;
900921
this._errorPrinter.appendChild(mainMessage);
901922
};
902923

903924
/**
904925
* @static
905-
* @method _makeStackTrace
926+
* @method _makeErrorDetail
906927
* @private
907928
*/
908-
Graphics._makeStackTrace = function(stack) {
909-
var stackTrace = document.createElement('div');
910-
var style = stackTrace.style;
929+
Graphics._makeErrorDetail = function(info, stack) {
930+
var detail = document.createElement('div');
931+
var style = detail.style;
911932
style.color = 'white';
912933
style.textAlign = 'left';
913934
style.fontSize = '18px';
914-
stackTrace.innerHTML = '<br><hr>' + stack + '<hr>';
915-
this._errorPrinter.appendChild(stackTrace);
935+
detail.innerHTML = '<br><hr>' + info + '<br><br>' + stack;
936+
this._errorPrinter.appendChild(detail);
937+
};
938+
939+
/**
940+
* @static
941+
* @method _formatEventInfo
942+
* @private
943+
*/
944+
Graphics._formatEventInfo = function(error) {
945+
switch (String(error.eventType)) {
946+
case "map_event":
947+
return "MapID: %1, MapEventID: %2, page: %3, line: %4".format(error.mapId, error.mapEventId, error.page, error.line);
948+
case "common_event":
949+
return "CommonEventID: %1, line: %2".format(error.commonEventId, error.line);
950+
case "battle_event":
951+
return "TroopID: %1, page: %2, line: %3".format(error.troopId, error.page, error.line);
952+
case "test_event":
953+
return "TestEvent, line: %1".format(error.line);
954+
default:
955+
return "No information";
956+
}
957+
};
958+
959+
/**
960+
* @static
961+
* @method _formatEventCommandInfo
962+
* @private
963+
*/
964+
Graphics._formatEventCommandInfo = function(error) {
965+
switch (String(error.eventCommand)) {
966+
case "plugin_command":
967+
return "◆Plugin Command: " + error.content;
968+
case "script":
969+
return "◆Script: " + error.content;
970+
case "conditional_branch_script":
971+
return "◆Conditional Branch(Script): " + error.content;
972+
case "set_route_script":
973+
return "◆Set Movement Route(Script): " + error.content;
974+
case "auto_route_script":
975+
return "Autonomous Movement Custom Route(Script): " + error.content;
976+
case "other":
977+
default:
978+
return "";
979+
}
916980
};
917981

918982
/**

js/rpg_managers/SceneManager.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ SceneManager.onKeyDown = function(event) {
200200
SceneManager.catchException = function(e) {
201201
if (e instanceof Error) {
202202
Graphics.printError(e.name, e.message);
203-
Graphics.printStackTrace(e.stack);
203+
Graphics.printErrorDetail(e);
204204
console.error(e.stack);
205205
} else {
206206
Graphics.printError('UnknownError', e);

js/rpg_objects/Game_Character.js

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ Game_Character.prototype.initMembers = function() {
6969
this._originalMoveRoute = null;
7070
this._originalMoveRouteIndex = 0;
7171
this._waitCount = 0;
72+
this._callerEventInfo = null;
7273
};
7374

7475
Game_Character.prototype.memorizeMoveRoute = function() {
@@ -80,6 +81,7 @@ Game_Character.prototype.restoreMoveRoute = function() {
8081
this._moveRoute = this._originalMoveRoute;
8182
this._moveRouteIndex = this._originalMoveRouteIndex;
8283
this._originalMoveRoute = null;
84+
this._callerEventInfo = null;
8385
};
8486

8587
Game_Character.prototype.isMoveRouteForcing = function() {
@@ -102,6 +104,10 @@ Game_Character.prototype.forceMoveRoute = function(moveRoute) {
102104
this._waitCount = 0;
103105
};
104106

107+
Game_Character.prototype.setCallerEventInfo = function(callerEventInfo) {
108+
this._callerEventInfo = callerEventInfo;
109+
};
110+
105111
Game_Character.prototype.updateStop = function() {
106112
Game_CharacterBase.prototype.updateStop.call(this);
107113
if (this._moveRouteForcing) {
@@ -262,7 +268,27 @@ Game_Character.prototype.processMoveCommand = function(command) {
262268
AudioManager.playSe(params[0]);
263269
break;
264270
case gc.ROUTE_SCRIPT:
265-
eval(params[0]);
271+
try {
272+
eval(params[0]);
273+
} catch (error) {
274+
if (this._callerEventInfo) {
275+
for (var key in this._callerEventInfo) {
276+
error[key] = this._callerEventInfo[key];
277+
}
278+
error.line += this._moveRouteIndex + 1;
279+
error.eventCommand = "set_route_script";
280+
error.content = command.parameters[0];
281+
} else {
282+
error.eventType = "map_event";
283+
error.mapId = this._mapId;
284+
error.mapEventId = this._eventId;
285+
error.page = this._pageIndex + 1;
286+
error.line = this._moveRouteIndex + 1;
287+
error.eventCommand = "auto_route_script";
288+
error.content = command.parameters[0];
289+
}
290+
throw error;
291+
}
266292
break;
267293
}
268294
};

js/rpg_objects/Game_CommonEvent.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Game_CommonEvent.prototype.update = function() {
4040
if (this._interpreter) {
4141
if (!this._interpreter.isRunning()) {
4242
this._interpreter.setup(this.list());
43+
this._interpreter.setEventInfo({ eventType: 'common_event', commonEventId: this._commonEventId });
4344
}
4445
this._interpreter.update();
4546
}

js/rpg_objects/Game_Event.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ Game_Event.prototype.updateParallel = function() {
322322
if (this._interpreter) {
323323
if (!this._interpreter.isRunning()) {
324324
this._interpreter.setup(this.list(), this._eventId);
325+
this._interpreter.setEventInfo(this.getEventInfo());
325326
}
326327
this._interpreter.update();
327328
}
@@ -336,3 +337,7 @@ Game_Event.prototype.forceMoveRoute = function(moveRoute) {
336337
Game_Character.prototype.forceMoveRoute.call(this, moveRoute);
337338
this._prelockDirection = 0;
338339
};
340+
341+
Game_Event.prototype.getEventInfo = function() {
342+
return { eventType: "map_event", mapId: this._mapId, mapEventId: this._eventId, page: this._pageIndex + 1 };
343+
};

js/rpg_objects/Game_Interpreter.js

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ Game_Interpreter.prototype.clear = function() {
3232
this._waitCount = 0;
3333
this._waitMode = '';
3434
this._comments = '';
35+
this._eventInfo = null;
3536
this._character = null;
3637
this._childInterpreter = null;
3738
};
@@ -52,9 +53,14 @@ Game_Interpreter.prototype.isOnCurrentMap = function() {
5253
return this._mapId === $gameMap.mapId();
5354
};
5455

56+
Game_Interpreter.prototype.setEventInfo = function(eventInfo) {
57+
this._eventInfo = eventInfo;
58+
};
59+
5560
Game_Interpreter.prototype.setupReservedCommonEvent = function() {
5661
if ($gameTemp.isCommonEventReserved()) {
5762
this.setup($gameTemp.reservedCommonEvent().list);
63+
this.setEventInfo({ eventType: 'common_event', commonEventId: $gameTemp.reservedCommonEventId() });
5864
$gameTemp.clearCommonEvent();
5965
return true;
6066
} else {
@@ -166,8 +172,17 @@ Game_Interpreter.prototype.executeCommand = function() {
166172
this._indent = command.indent;
167173
var methodName = 'command' + command.code;
168174
if (typeof this[methodName] === 'function') {
169-
if (!this[methodName]()) {
170-
return false;
175+
try {
176+
if (!this[methodName]()) {
177+
return false;
178+
}
179+
} catch (error) {
180+
for (var key in this._eventInfo) {
181+
error[key] = this._eventInfo[key];
182+
}
183+
error.eventCommand = error.eventCommand || "other";
184+
error.line = error.line || this._index + 1;
185+
throw error;
171186
}
172187
}
173188
this._index++;
@@ -543,7 +558,13 @@ Game_Interpreter.prototype.command111 = function() {
543558
result = Input.isPressed(this._params[1]);
544559
break;
545560
case 12: // Script
546-
result = !!eval(this._params[1]);
561+
try {
562+
result = !!eval(this._params[1]);
563+
} catch (error) {
564+
error.eventCommand = "conditional_branch_script";
565+
error.content = this._params[1];
566+
throw error;
567+
}
547568
break;
548569
case 13: // Vehicle
549570
result = ($gamePlayer.vehicle() === $gameMap.vehicle(this._params[1]));
@@ -616,6 +637,7 @@ Game_Interpreter.prototype.command117 = function() {
616637
Game_Interpreter.prototype.setupChild = function(list, eventId) {
617638
this._childInterpreter = new Game_Interpreter(this._depth + 1);
618639
this._childInterpreter.setup(list, eventId);
640+
this._childInterpreter.setEventInfo({ eventType: 'common_event', commonEventId: this._params[0] });
619641
};
620642

621643
// Label
@@ -1024,6 +1046,9 @@ Game_Interpreter.prototype.command205 = function() {
10241046
this._character = this.character(this._params[0]);
10251047
if (this._character) {
10261048
this._character.forceMoveRoute(this._params[1]);
1049+
var eventInfo = JsonEx.makeDeepCopy(this._eventInfo);
1050+
eventInfo.line = this._index + 1;
1051+
this._character.setCallerEventInfo(eventInfo);
10271052
if (this._params[1].wait) {
10281053
this.setWaitMode('route');
10291054
}
@@ -1731,20 +1756,36 @@ Game_Interpreter.prototype.command354 = function() {
17311756

17321757
// Script
17331758
Game_Interpreter.prototype.command355 = function() {
1759+
var startLine = this._index + 1;
1760+
var postfix = this.nextEventCode() === 655 ? "..." : "";
17341761
var script = this.currentCommand().parameters[0] + '\n';
17351762
while (this.nextEventCode() === 655) {
17361763
this._index++;
17371764
script += this.currentCommand().parameters[0] + '\n';
17381765
}
1739-
eval(script);
1766+
var endLine = this._index + 1;
1767+
try {
1768+
eval(script);
1769+
} catch (error) {
1770+
error.line = startLine + "-" + endLine;
1771+
error.eventCommand = "script";
1772+
error.content = this._params[0] + postfix;
1773+
throw error;
1774+
}
17401775
return true;
17411776
};
17421777

17431778
// Plugin Command
17441779
Game_Interpreter.prototype.command356 = function() {
17451780
var args = this._params[0].split(" ");
17461781
var command = args.shift();
1747-
this.pluginCommand(command, args);
1782+
try {
1783+
this.pluginCommand(command, args);
1784+
} catch (error) {
1785+
error.eventCommand = "plugin_command";
1786+
error.content = this._params[0];
1787+
throw error;
1788+
}
17481789
return true;
17491790
};
17501791

js/rpg_objects/Game_Map.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -756,6 +756,7 @@ Game_Map.prototype.setupStartingEvent = function() {
756756
Game_Map.prototype.setupTestEvent = function() {
757757
if ($testEvent) {
758758
this._interpreter.setup($testEvent, 0);
759+
this._interpreter.setEventInfo({ eventType: 'test_event' });
759760
$testEvent = null;
760761
return true;
761762
}
@@ -769,6 +770,7 @@ Game_Map.prototype.setupStartingMapEvent = function() {
769770
if (event.isStarting()) {
770771
event.clearStartingFlag();
771772
this._interpreter.setup(event.list(), event.eventId());
773+
this._interpreter.setEventInfo(event.getEventInfo());
772774
return true;
773775
}
774776
}
@@ -780,6 +782,7 @@ Game_Map.prototype.setupAutorunCommonEvent = function() {
780782
var event = $dataCommonEvents[i];
781783
if (event && event.trigger === 1 && $gameSwitches.value(event.switchId)) {
782784
this._interpreter.setup(event.list);
785+
this._interpreter.setEventInfo({ eventType: 'common_event', commonEventId: i });
783786
return true;
784787
}
785788
}

js/rpg_objects/Game_Temp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ Game_Temp.prototype.reservedCommonEvent = function() {
3434
return $dataCommonEvents[this._commonEventId];
3535
};
3636

37+
Game_Temp.prototype.reservedCommonEventId = function() {
38+
return this._commonEventId;
39+
};
40+
3741
Game_Temp.prototype.setDestination = function(x, y) {
3842
this._destinationX = x;
3943
this._destinationY = y;

js/rpg_objects/Game_Troop.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ Game_Troop.prototype.setupBattleEvent = function() {
159159
var page = pages[i];
160160
if (this.meetsConditions(page) && !this._eventFlags[i]) {
161161
this._interpreter.setup(page.list);
162+
this._interpreter.setEventInfo({ eventType: 'battle_event', troopId: this._troopId, page: i + 1 });
162163
if (page.span <= 1) {
163164
this._eventFlags[i] = true;
164165
}

0 commit comments

Comments
 (0)