Skip to content

Commit 9da1a1e

Browse files
committed
fix(jsbattle-engine): fix error handling when creating AI from incorrect input
1 parent 3bbc013 commit 9da1a1e

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

packages/jsbattle-docs/docs/configuration.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ List of all settings of JsBattle:
8484
// define each provider as separate object
8585
{
8686
// name of provider. Supported values are: github, facebook, google
87-
// authStrategies['github'] = require("passport-github2");
88-
"name": 'github',
87+
// authStrategies["github"] = require("passport-github2");
88+
"name": "github",
8989

9090
// client ID generated by OAuth provider
9191
"clientID": "XXXXXXXXXXXXXXXXXXXX",

packages/jsbattle-engine/src/engine/AiDefinition.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,9 @@ class AiDefinition {
145145
*/
146146
fromCode(tankName, code, initData) {
147147
if(!tankName) throw "tankName is required";
148-
if(code === undefined) throw "Code is required";
148+
if(!code) throw "Code is required";
149+
if(typeof(tankName) != 'string') throw "tankName must be a string";
150+
if(typeof(code) != 'string') throw "code must be a string";
149151
code = code.replace(/importScripts\w*\([^\)]*\)/g, '');
150152
this._name = tankName;
151153
this._code = code;

packages/jsbattle-webpage/src/components/LiveCode.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,12 @@ class LiveCode extends React.Component {
6565
let aiList = [];
6666
for(let i = 0; i < count; i++) {
6767
let ai = JsBattle.createAiDefinition();
68-
ai.fromCode(this.props.name, code);
68+
try {
69+
ai.fromCode(this.props.name, code);
70+
} catch(err) {
71+
console.error('Unable to create AI "' + this.props.name + '" from code', code);
72+
console.error(err);
73+
}
6974
aiList.push(ai);
7075
}
7176
return template.concat(aiList);

0 commit comments

Comments
 (0)