mirror of
https://github.com/openfrontio/OpenFrontIO.git
synced 2026-06-21 13:10:42 +00:00
update archive error handling
This commit is contained in:
@@ -240,7 +240,7 @@
|
||||
* better emojis 🏳️🤦♂️🖕☮️🫡😡😈🤡 DONE 12/13/2024
|
||||
* store ips in bigquery table DONE 12/14/2024
|
||||
* better error logging in server DONE 12/16/2024
|
||||
* store and archive player cookies
|
||||
* store and archive player cookies DONE 12/17/2024
|
||||
* make ips less precise
|
||||
* send client logs back to server
|
||||
* seperate server config from client config
|
||||
|
||||
+39
-6
@@ -5,7 +5,6 @@ import { BigQuery } from '@google-cloud/bigquery';
|
||||
const storage = new Storage();
|
||||
const bigquery = new BigQuery();
|
||||
|
||||
|
||||
export async function archive(gameRecord: GameRecord) {
|
||||
try {
|
||||
// Save metadata to BigQuery
|
||||
@@ -27,19 +26,21 @@ export async function archive(gameRecord: GameRecord) {
|
||||
})),
|
||||
};
|
||||
|
||||
await bigquery
|
||||
const [apiResponse] = await bigquery
|
||||
.dataset('game_archive')
|
||||
.table('game_results')
|
||||
.insert([row]);
|
||||
|
||||
console.log(`wrote game metadata to BigQuery: ${gameRecord.id}`);
|
||||
|
||||
if (gameRecord.turns.length > 0) {
|
||||
// Players may see this so make sure to clear PII.
|
||||
// Players may see this so make sure to clear PII
|
||||
gameRecord.players.forEach(p => {
|
||||
p.ip = "REDACTED"
|
||||
p.persistentID = "REDACTED"
|
||||
})
|
||||
console.log(`writing game ${gameRecord.id} to gcs`)
|
||||
});
|
||||
|
||||
console.log(`writing game ${gameRecord.id} to gcs`);
|
||||
const bucket = storage.bucket("openfront-games");
|
||||
const file = bucket.file(gameRecord.id);
|
||||
await file.save(JSON.stringify(GameRecordSchema.parse(gameRecord)), {
|
||||
@@ -47,6 +48,38 @@ export async function archive(gameRecord: GameRecord) {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`error archiving game record: ${error}`)
|
||||
try {
|
||||
console.error(`Error archiving game ${gameRecord.id}:`);
|
||||
|
||||
if (Array.isArray(error?.errors)) {
|
||||
// Handle BigQuery insertion errors which come as an array
|
||||
error.errors.forEach((err, index) => {
|
||||
console.error(`${gameRecord.id}: Archive Error ${index + 1}:`, {
|
||||
reason: err.reason,
|
||||
message: err.message,
|
||||
location: err.location,
|
||||
debugInfo: err.debugInfo
|
||||
});
|
||||
});
|
||||
} else if (error?.code) {
|
||||
// Handle Google Cloud Storage errors which typically have error codes
|
||||
console.error(`${gameRecord.id}: Archive: Storage error:`, {
|
||||
code: error.code,
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
details: error.errors
|
||||
});
|
||||
} else {
|
||||
// Handle generic errors
|
||||
console.error(`${gameRecord.id}: Archive: Unexpected error:`, {
|
||||
message: error?.message || error,
|
||||
stack: error?.stack,
|
||||
name: error?.name,
|
||||
...(error && typeof error === 'object' ? error : {})
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
console.log(`error handling archive error: ${error}`)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user