mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-26 03:44:36 +00:00
don't log zod validation errors
This commit is contained in:
@@ -153,7 +153,7 @@
|
||||
</g>
|
||||
</svg>
|
||||
<div class="flex justify-center text-sm font-bold mt-[-5px] logo-version">
|
||||
v0.16.0
|
||||
v0.16.5
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -121,9 +121,13 @@ async function archiveToGCS(gameRecord: GameRecord) {
|
||||
});
|
||||
|
||||
const file = bucket.file(recordCopy.id);
|
||||
await file.save(JSON.stringify(GameRecordSchema.parse(recordCopy)), {
|
||||
contentType: "application/json",
|
||||
});
|
||||
try {
|
||||
await file.save(JSON.stringify(recordCopy), {
|
||||
contentType: "application/json",
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`error saving game ${gameRecord.id}`);
|
||||
}
|
||||
|
||||
console.log(`${gameRecord.id}: game record successfully written to GCS`);
|
||||
}
|
||||
@@ -142,11 +146,7 @@ export async function readGameRecord(gameId: GameID): Promise<GameRecord> {
|
||||
const [content] = await file.download();
|
||||
const gameRecord = JSON.parse(content.toString());
|
||||
|
||||
// Validate the parsed content against the schema
|
||||
const validatedRecord = GameRecordSchema.parse(gameRecord);
|
||||
|
||||
console.log(`${gameId}: Successfully read game record from GCS`);
|
||||
return validatedRecord;
|
||||
return gameRecord as GameRecord;
|
||||
} catch (error) {
|
||||
console.error(`${gameId}: Error reading game record from GCS: ${error}`, {
|
||||
message: error?.message || error,
|
||||
|
||||
+31
-18
@@ -130,9 +130,12 @@ export class GameServer {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const clientMsg: ClientMessage = ClientMessageSchema.parse(
|
||||
JSON.parse(message),
|
||||
);
|
||||
let clientMsg: ClientMessage = null;
|
||||
try {
|
||||
clientMsg = ClientMessageSchema.parse(JSON.parse(message));
|
||||
} catch (error) {
|
||||
throw Error(`error parsing schema for ${client.ip}`);
|
||||
}
|
||||
if (this.allClients.has(clientMsg.clientID)) {
|
||||
const client = this.allClients.get(clientMsg.clientID);
|
||||
if (client.persistentID != clientMsg.persistentID) {
|
||||
@@ -221,15 +224,19 @@ export class GameServer {
|
||||
}
|
||||
|
||||
private sendStartGameMsg(ws: WebSocket, lastTurn: number) {
|
||||
ws.send(
|
||||
JSON.stringify(
|
||||
ServerStartGameMessageSchema.parse({
|
||||
type: "start",
|
||||
turns: this.turns.slice(lastTurn),
|
||||
config: this.gameConfig,
|
||||
}),
|
||||
),
|
||||
);
|
||||
try {
|
||||
ws.send(
|
||||
JSON.stringify(
|
||||
ServerStartGameMessageSchema.parse({
|
||||
type: "start",
|
||||
turns: this.turns.slice(lastTurn),
|
||||
config: this.gameConfig,
|
||||
}),
|
||||
),
|
||||
);
|
||||
} catch (error) {
|
||||
throw new Error(`error sending start message for game ${this.id}`);
|
||||
}
|
||||
}
|
||||
|
||||
private endTurn() {
|
||||
@@ -241,12 +248,18 @@ export class GameServer {
|
||||
this.turns.push(pastTurn);
|
||||
this.intents = [];
|
||||
|
||||
const msg = JSON.stringify(
|
||||
ServerTurnMessageSchema.parse({
|
||||
type: "turn",
|
||||
turn: pastTurn,
|
||||
}),
|
||||
);
|
||||
let msg = "";
|
||||
try {
|
||||
msg = JSON.stringify(
|
||||
ServerTurnMessageSchema.parse({
|
||||
type: "turn",
|
||||
turn: pastTurn,
|
||||
}),
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(`error sending message for game ${this.id}`);
|
||||
return;
|
||||
}
|
||||
this.activeClients.forEach((c) => {
|
||||
c.ws.send(msg);
|
||||
});
|
||||
|
||||
+24
-14
@@ -201,7 +201,6 @@ app.post(
|
||||
return;
|
||||
}
|
||||
gameRecord.players.forEach((p) => (p.ip = clientIP));
|
||||
GameRecordSchema.parse(gameRecord);
|
||||
archive(gameRecord);
|
||||
res.json({
|
||||
success: true,
|
||||
@@ -306,9 +305,12 @@ wss.on("connection", (ws, req) => {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const clientMsg: ClientMessage = ClientMessageSchema.parse(
|
||||
JSON.parse(message.toString()),
|
||||
);
|
||||
let clientMsg: ClientMessage = null;
|
||||
try {
|
||||
clientMsg = ClientMessageSchema.parse(JSON.parse(message.toString()));
|
||||
} catch (error) {
|
||||
throw new Error(`error parsing zod schema for ip: ${ip}`);
|
||||
}
|
||||
if (clientMsg.type == "join") {
|
||||
const forwarded = req.headers["x-forwarded-for"];
|
||||
let ip = Array.isArray(forwarded)
|
||||
@@ -339,15 +341,18 @@ wss.on("connection", (ws, req) => {
|
||||
if (!wasFound) {
|
||||
console.log(`game ${clientMsg.gameID} not found, loading from gcs`);
|
||||
const record = await readGameRecord(clientMsg.gameID);
|
||||
ws.send(
|
||||
JSON.stringify(
|
||||
ServerStartGameMessageSchema.parse({
|
||||
type: "start",
|
||||
turns: record.turns,
|
||||
config: record.gameConfig,
|
||||
}),
|
||||
),
|
||||
);
|
||||
|
||||
let startGame = null;
|
||||
try {
|
||||
startGame = ServerStartGameMessageSchema.parse({
|
||||
type: "start",
|
||||
turns: record.turns,
|
||||
config: record.gameConfig,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log(`error validating schema for ip ${ip}`);
|
||||
}
|
||||
ws.send(JSON.stringify(startGame));
|
||||
}
|
||||
}
|
||||
if (clientMsg.type == "log") {
|
||||
@@ -361,7 +366,12 @@ wss.on("connection", (ws, req) => {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.warn(`errror handling websocket message for ${ip}: ${error}`);
|
||||
console.warn(
|
||||
`error handling websocket message for ${ip}: ${error}`.substring(
|
||||
0,
|
||||
250,
|
||||
),
|
||||
);
|
||||
}
|
||||
});
|
||||
ws.on("error", (error: Error) => {
|
||||
|
||||
Reference in New Issue
Block a user