Skip to content

Commit 4e3d4ea

Browse files
author
Julien Poulton
committed
Merge branch 'fix-runtime-errors' into 'master'
fix(SDK): fails properly reported in test.html, even when caught by user See merge request codingame/game-engine!199
2 parents 3c320a8 + 836e1aa commit 4e3d4ea

File tree

3 files changed

+40
-32
lines changed

3 files changed

+40
-32
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ target/
55
.project
66
.vscode
77
/bin
8-
*.iml
8+
*.iml

engine/core/src/main/java/com/codingame/gameengine/core/GameManager.java

Lines changed: 36 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -172,42 +172,48 @@ void start(InputStream is, PrintStream out) {
172172
* The amount of expected output lines from the player.
173173
*/
174174
protected void execute(T player, int nbrOutputLines) {
175-
if (!this.initDone) {
176-
throw new RuntimeException("Impossible to execute a player during init phase.");
177-
}
175+
try {
176+
if (!this.initDone) {
177+
throw new RuntimeException("Impossible to execute a player during init phase.");
178+
}
178179

179-
player.setTimeout(false);
180+
player.setTimeout(false);
180181

181-
InputCommand iCmd = InputCommand.parse(s.nextLine());
182+
InputCommand iCmd = InputCommand.parse(s.nextLine());
182183

183-
if (iCmd.cmd != InputCommand.Command.GET_GAME_INFO) {
184-
throw new RuntimeException("Invalid command: " + iCmd.cmd);
185-
}
184+
if (iCmd.cmd != InputCommand.Command.GET_GAME_INFO) {
185+
throw new RuntimeException("Invalid command: " + iCmd.cmd);
186+
}
186187

187-
dumpView();
188-
dumpInfos();
189-
dumpNextPlayerInput(player.getInputs().toArray(new String[0]));
190-
if (nbrOutputLines > 0) {
191-
addTurnTime();
192-
}
193-
dumpNextPlayerInfos(player.getIndex(), nbrOutputLines, player.hasNeverBeenExecuted() ? firstTurnMaxTime : turnMaxTime);
194-
195-
// READ PLAYER OUTPUTS
196-
iCmd = InputCommand.parse(s.nextLine());
197-
if (iCmd.cmd == InputCommand.Command.SET_PLAYER_OUTPUT) {
198-
List<String> output = new ArrayList<>(iCmd.lineCount);
199-
for (int i = 0; i < iCmd.lineCount; i++) {
200-
output.add(s.nextLine());
188+
dumpView();
189+
dumpInfos();
190+
dumpNextPlayerInput(player.getInputs().toArray(new String[0]));
191+
if (nbrOutputLines > 0) {
192+
addTurnTime();
193+
}
194+
dumpNextPlayerInfos(player.getIndex(), nbrOutputLines, player.hasNeverBeenExecuted() ? firstTurnMaxTime : turnMaxTime);
195+
196+
// READ PLAYER OUTPUTS
197+
iCmd = InputCommand.parse(s.nextLine());
198+
if (iCmd.cmd == InputCommand.Command.SET_PLAYER_OUTPUT) {
199+
List<String> output = new ArrayList<>(iCmd.lineCount);
200+
for (int i = 0; i < iCmd.lineCount; i++) {
201+
output.add(s.nextLine());
202+
}
203+
player.setOutputs(output);
204+
} else if (iCmd.cmd == InputCommand.Command.SET_PLAYER_TIMEOUT) {
205+
player.setTimeout(true);
206+
} else {
207+
throw new RuntimeException("Invalid command: " + iCmd.cmd);
201208
}
202-
player.setOutputs(output);
203-
} else if (iCmd.cmd == InputCommand.Command.SET_PLAYER_TIMEOUT) {
204-
player.setTimeout(true);
205-
} else {
206-
throw new RuntimeException("Invalid command: " + iCmd.cmd);
207-
}
208209

209-
player.resetInputs();
210-
newTurn = false;
210+
player.resetInputs();
211+
newTurn = false;
212+
} catch (RuntimeException e) {
213+
//Don't let the user catch game fail exceptions
214+
dumpFail(e);
215+
throw e;
216+
}
211217
}
212218

213219
/**

runner/src/main/resources/view/app.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ function PlayerCtrl ($scope, $timeout, $interval, $filter, drawerFactory, gameMa
7272
return
7373
}
7474
if (ctrl.data.failCause) {
75-
addError(ctrl.data.failCause)
75+
addError({
76+
message: ctrl.data.failCause
77+
})
7678
return
7779
}
7880

0 commit comments

Comments
 (0)