Fix crash log file not found error in spike #12

Merged
probablycorey merged 1 commits from probablycorey/fix-crash-log-path into main 2026-03-10 16:54:32 +00:00
Showing only changes of commit c9fc834f4e - Show all commits

View File

@ -1,5 +1,12 @@
import { mkdirSync } from "node:fs"
import { getConfig } from "../config"
import { log } from "../log"
const crashLogDir = getConfig("dataDir")
mkdirSync(crashLogDir, { recursive: true })
const crashLogPath = `${crashLogDir}/crash.log`
export const logCrash = async (error: unknown) => {
try {
const stack = error instanceof Error ? error.stack : ""
@ -8,7 +15,7 @@ export const logCrash = async (error: unknown) => {
const crashLog = `Spike crashed at ${new Date().toISOString()}:\n${message}\n${stack ?? ""}\n`
// overwrite the crash log file
const file = Bun.file(`${process.env.DATA_DIR}/crash.log`)
const file = Bun.file(crashLogPath)
file.write(crashLog)
} catch (writeError) {
log({ type: "error", error: writeError, context: "writing crash log" })
@ -33,7 +40,7 @@ export const alertAboutCrashLog = async (client: any) => {
const clearCrashLog = async () => {
try {
const file = Bun.file(`${process.env.DATA_DIR}/crash.log`)
const file = Bun.file(crashLogPath)
if (!(await file.exists())) return
const contents = await file.text()
await file.write("")