diff --git a/dyk-counts/eventstream-trigger.ts b/dyk-counts/eventstream-trigger.ts index 0ad8d9d..0a60bf1 100644 --- a/dyk-counts/eventstream-trigger.ts +++ b/dyk-counts/eventstream-trigger.ts @@ -59,7 +59,8 @@ export default class DykCounts extends Route { const keyValues = queryResult.flatMap(e => [e.username, e.noms]) as string[]; await redis.del('dyk-counts').catch(e => this.redisError(e)); - await redis.hmset.apply(null, ['dyk-counts'].concat(keyValues)).catch(e => this.redisError(e)); + const redisArgs = ['dyk-counts'].concat(keyValues) as [string, ...string[]]; // TS: array with at least one element + await redis.hmset(...redisArgs).catch(e => this.redisError(e)); } catch (e) { this.log(`[E] Error while running db refresh`, e); } @@ -127,6 +128,6 @@ export default class DykCounts extends Route { if (err.command === 'HMSET') { err.args = [err.args[0], '']; // too big to log! } - this.log(`[E] Redis error: `, err) + this.log(`[E] dyk-counts redis error: `, err) } } diff --git a/redis-io.ts b/redis-io.ts index edccb99..e58fa4e 100644 --- a/redis-io.ts +++ b/redis-io.ts @@ -1,5 +1,6 @@ import {Redis} from "ioredis" import {onToolforge, readFile} from "./utils"; +import {log} from "./botbase"; export const redis = new Redis({ host: onToolforge() ? 'tools-redis' : 'localhost', @@ -9,3 +10,8 @@ export const redis = new Redis({ // A secret prefix string is stored in redis-key-prefix.txt keyPrefix: readFile(__dirname + '/redis-key-prefix.txt'), }); + +redis.on('error', err => { + log(`[E] Redis error:`); + log(err); +}); diff --git a/utils.ts b/utils.ts index c9577fa..e5ca7e5 100644 --- a/utils.ts +++ b/utils.ts @@ -30,6 +30,8 @@ export function createLogStream(file: string) { let stringified; if (typeof msg === 'string') { stream.write(`[${ts}] ${msg}\n`); + } else if (msg instanceof Error) { + stream.write(`[${ts}] ${msg.stack}`) } else if (stringified = stringifyObject(msg)) { stream.write(`[${ts}] ${stringified}\n`); } else {