Skip to content

Commit a348bd7

Browse files
committed
add even more logging
1 parent e8a2f56 commit a348bd7

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

src/data/Thread.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,18 +1122,28 @@ export class Thread {
11221122
}
11231123

11241124
public async getDMChannel(): Promise<DMChannel> {
1125-
const user = await bot.users.fetch(this.user_id);
1126-
const dmChannel = await user.createDM();
1125+
try {
1126+
const user = await bot.users.fetch(this.user_id);
1127+
const dmChannel = await user.createDM();
11271128

1128-
return dmChannel;
1129+
return dmChannel;
1130+
} catch (err) {
1131+
logger.error({ thread_id: this.id, user_id: this.user_id, err });
1132+
throw err;
1133+
}
11291134
}
11301135

11311136
public async getThreadChannel(): Promise<SendableChannels> {
1132-
const channel = await bot.channels.fetch(this.channel_id);
1137+
try {
1138+
const channel = await bot.channels.fetch(this.channel_id);
11331139

1134-
if (channel?.isSendable()) return channel;
1140+
if (channel?.isSendable()) return channel;
11351141

1136-
throw "it was impossible to retrieve the thread channel";
1142+
throw "it was impossible to retrieve the thread channel";
1143+
} catch (err) {
1144+
logger.error({ thread_id: this.id, user_id: this.user_id, err });
1145+
throw err;
1146+
}
11371147
}
11381148

11391149
public async sendInfoHeader(

src/data/threads.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,14 @@ export async function createNewThreadForUser(
168168
// We can safely discard this error, because it just means we couldn't find the member in the guild
169169
// Which - for obvious reasons - is completely okay.
170170
if ((e as DiscordAPIError).code !== 10007) {
171-
logger.error({
171+
logger.debug({
172172
discord_api_code: (e as DiscordAPIError).code,
173173
err: e,
174174
});
175+
} else {
176+
logger.error({
177+
err: e,
178+
});
175179
}
176180
}
177181
}

src/index.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { start } from "./main";
99
import { migrateAllUp } from "./migrate";
1010
import { PluginInstallationError } from "./PluginInstallationError";
1111
import web from "./web";
12+
import logger from "./logger";
1213

1314
const bunVersion = process.versions.bun.split(".").map(parseInt) as [
1415
number,
@@ -112,6 +113,8 @@ modules.forEach((mod) => {
112113
(async () => {
113114
await migrateAllUp();
114115

116+
logger.info(`Pino opened on level ${process.env.PINO_LOG_LEVEL}`);
117+
115118
// Start the bot
116119
start(bot);
117120

0 commit comments

Comments
 (0)