Skip to content

Commit 876c280

Browse files
Merge branch '6686-cgcontribution-uncaught-exception-when-trying-to-parse-an-incorrect-json-maybe-spritesheet' into 'master'
6686 cgcontribution uncaught exception when trying to parse an incorrect json maybe spritesheet See merge request codingame/game-engine!249
2 parents 9d2e3bd + 4b8daa8 commit 876c280

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

playground/misc/misc-3-release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The CodinGame SDK is regularly updated and improved. This document lets you know what changed in the latest releases.
44

5+
## NEXT RELEASE
6+
7+
### 🐞 Bug fix
8+
9+
- Fixed crashes when invalid JSON files are in assets folder
10+
511
## 3.9.0
612

713
### 🎁 Features

runner/src/main/java/com/codingame/gameengine/runner/Renderer.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ private static void generateAssetsFile(Path tmpdir, String assetsPath) {
258258
if (!fonts.contains(new JsonPrimitive(newName))) {
259259
fonts.add(newName);
260260
}
261-
261+
262262
Files.write(
263263
tmpdir.resolve("hashed_assets").resolve(newName),
264264
newContent.getBytes(),
@@ -284,6 +284,9 @@ private static void generateAssetsFile(Path tmpdir, String assetsPath) {
284284
);
285285
}
286286
}
287+
} catch (JsonSyntaxException e) {
288+
log.error("Invalid JSON in file " + f.getFileName() + " at " + f.toString().replaceAll("^" + tmpdir.toString(), ""));
289+
e.printStackTrace();
287290
} catch (IOException e) {
288291
e.printStackTrace();
289292
}
@@ -526,8 +529,8 @@ private void checkQuestionsTypeValidity(GameConfig gameConfig, QuestionConfig qu
526529
throw new MissingConfigException("An optimization game must have a sorting_order property in config.ini.");
527530
} else if (!"ASC".equalsIgnoreCase(questionConfig.getSortingOrder())
528531
&& !"DESC".equalsIgnoreCase(questionConfig.getSortingOrder())) {
529-
throw new MissingConfigException("The sorting order for an optimization game must be ASC (ascendant) or DESC (descendant)");
530-
}
532+
throw new MissingConfigException("The sorting order for an optimization game must be ASC (ascendant) or DESC (descendant)");
533+
}
531534
}
532535

533536
switch (gameConfig.getGameType()) {
@@ -679,7 +682,8 @@ public void handleRequest(HttpServerExchange exchange) throws Exception {
679682
}
680683

681684
exchange.setStatusCode(StatusCodes.OK);
682-
} if (exchange.getRelativePath().equals("/stub")) {
685+
}
686+
if (exchange.getRelativePath().equals("/stub")) {
683687
File stubFile = sourceFolderPath.resolve("config/stub.txt").toFile();
684688
if (exchange.getRequestMethod().equalToString("GET")) {
685689
String stub = FileUtils.readFileToString(stubFile, StandardCharsets.UTF_8);

0 commit comments

Comments
 (0)