Various error log improvements #100
1 changed files with 5 additions and 0 deletions
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.
commit
023432cc11
5
start.js
5
start.js
|
|
@ -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 => {
|
||||||
|
|
|||||||
|
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) => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue
I don't want to apply the
unhandledRejectionchange 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
errorevents too.