From 97818e5080600dc68c65dcf9d1cd05411dd43b20 Mon Sep 17 00:00:00 2001 From: Mischa Untaga <99098079+MischaU8@users.noreply.github.com> Date: Fri, 16 Feb 2024 15:07:17 +0100 Subject: only write game data if it doesn't exist, write crash data if we dont stop on crashes --- rtt-module.js | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/rtt-module.js b/rtt-module.js index 4996f75..764e6e0 100755 --- a/rtt-module.js +++ b/rtt-module.js @@ -172,7 +172,6 @@ function log_crash(error, ctx, action=undefined, args=undefined) { // console.log() // console.log("VIEW", ctx.view) let line = `ERROR=${error.name}` - line += " SETUP=" + JSON.stringify(ctx.replay[0][2]) line += ` STEP=${ctx.step} ACTIVE=${ctx.active} STATE=${ctx.state?.state}` if (action !== undefined) { line += ` ACTION=${action}` @@ -190,20 +189,30 @@ function log_crash(error, ctx, action=undefined, args=undefined) { replay: ctx.replay, } - const shasum = crypto.createHash('sha1') - shasum.update(ctx.data) - const hash = shasum.digest('hex') + const data_checksum = crypto.createHash('sha1') + data_checksum.update(ctx.data) + const data_hash = data_checksum.digest('hex') - const out_file = `crash-${hash}.json` - line += ` DUMP=${out_file}` - fs.writeFileSync(out_file, JSON.stringify(game)) + const game_checksum = crypto.createHash('sha1') + game_checksum.update(JSON.stringify(game)) + const game_hash = game_checksum.digest('hex') + const crash_file = `crash-${data_hash}` + const out_file = `crash-${game_hash}.json` + line += " SETUP=" + JSON.stringify(ctx.replay[0][2]) + line += ` DATA=${data_hash} DUMP=${out_file}` if (error.message) line += " MSG=" + JSON.stringify(error.message.replace(/^Error: /, '')) - console.log(line) - if (!NO_CRASH) + if (!fs.existsSync(out_file)) { + fs.writeFileSync(out_file, JSON.stringify(game)) + console.log(line) + if (NO_CRASH) + fs.writeFileSync(crash_file, ctx.data) + } + if (!NO_CRASH) { throw error + } } // Custom Error classes, allowing us to ignore expected errors with -x -- cgit v1.2.3