Various error log improvements #100

Open
l1s5 wants to merge 6 commits from l1s5/out-of-your-element:log-improvements into main
Showing only changes of commit 023432cc11 - Show all commits

start: add process-wide rejection handler with error logger

Note that this also means that unhandled rejections now longer crashes
the program, it just logs the error and continues as usual.
l1s5 2026-10-25 08:49:31 +09:00
Signed by untrusted user: l1s5
GPG key ID: D0A90CC905B58D9B

View file

@ -8,6 +8,7 @@ process.title = "ooye"
require("temporal-polyfill-lite/global") require("temporal-polyfill-lite/global")
const fs = require("fs") const fs = require("fs")
const util = require("util")
const sqlite = require("better-sqlite3") const sqlite = require("better-sqlite3")
const migrate = require("./src/db/migrate") const migrate = require("./src/db/migrate")
const HeatSync = require("heatsync") const HeatSync = require("heatsync")
@ -16,6 +17,10 @@ const {reg} = require("./src/matrix/read-registration")
const passthrough = require("./src/passthrough") const passthrough = require("./src/passthrough")
const db = new sqlite("ooye.db") const db = new sqlite("ooye.db")
process.on("unhandledRejection", e => {

I don't want to apply the unhandledRejection change because the process dying has helped me notice a few bugs that I wouldn't have noticed otherwise. If there's an error, I want to fix it at the source, not suppress it and pretend everything's okay. Auto-restart is a great choice for everyone else.

This is incomplete at the goal of preventing crashes anyway because you need to deal with error events too.

I don't want to apply the `unhandledRejection` change because the process dying has helped me notice a few bugs that I wouldn't have noticed otherwise. If there's an error, I want to fix it at the source, not suppress it and pretend everything's okay. Auto-restart is a great choice for everyone else. This is incomplete at the goal of preventing crashes anyway because you need to deal with `error` events too.
console.error(`Unhandled promise rejection:\n${util.inspect(e, false, 4, false)}`)
})
const sync = new HeatSync({ const sync = new HeatSync({
watchFunction(path, options, cb) { watchFunction(path, options, cb) {
return fs.watchFile(path, options, (curr, prev) => { return fs.watchFile(path, options, (curr, prev) => {