standardize error messages

This commit is contained in:
bignutty 2024-12-26 23:17:46 +01:00
parent 295072d388
commit e523b5402e
4 changed files with 15 additions and 11 deletions

View file

@ -1,7 +1,7 @@
const { ClusterManager } = require('detritus-client'); const { ClusterManager } = require('detritus-client');
const superagent = require('superagent') const superagent = require('superagent')
const { basecamp } = require('#logging'); const { basecamp, formatErrorMessage } = require('#logging');
// Configure environment // Configure environment
require('dotenv').config(); require('dotenv').config();
@ -27,11 +27,10 @@ const manager = new ClusterManager(client, token, {
// Logging // Logging
manager.on("clusterProcess", ({ clusterProcess }) => { manager.on("clusterProcess", ({ clusterProcess }) => {
clusterProcess.on('close', ({code, signal}) => { clusterProcess.on('close', ({code, signal}) => {
basecamp(`<:ico_w4:1086624964284788787>\`[${process.env.HOSTNAME || "labscore"}]\` **\` CLUSTER_CLOSED \`** Cluster ${clusterProcess.clusterId} closed with code \`${code}\` and signal \`${signal}\` @ \`${Date.now()}\``) basecamp(formatErrorMessage(4, "CLUSTER_CLOSED", `Cluster ${clusterProcess.clusterId} closed with code \`${code}\` and signal \`${signal}\``));
}); });
clusterProcess.on('warn', async ({error}) => { clusterProcess.on('warn', async ({error}) => {
await basecamp(`<:ico_w2:1086624961025810485>\`[${process.env.HOSTNAME || "labscore"}]\` **\` CLUSTER_WARNING \`** Cluster ${clusterProcess.clusterId} issued warning @ \`${Date.now()}\``) await basecamp(formatErrorMessage(2, "CLUSTER_WARNING", `Cluster ${clusterProcess.clusterId} issued warning\n\`\`\`js\n${error}\`\`\``));
await basecamp(`\`\`\`js\n${error}\`\`\``)
}); });
}) })

View file

@ -85,7 +85,7 @@ const interactionClient = new InteractionCommandClient(cluster, {
useClusterClient: true useClusterClient: true
}) })
const { maintower, basecamp, ingest } = require('#logging'); const { maintower, basecamp, ingest, formatErrorMessage } = require('#logging');
const { createEmbed } = require('#utils/embed'); const { createEmbed } = require('#utils/embed');
const { icon, highlight } = require('#utils/markdown'); const { icon, highlight } = require('#utils/markdown');
@ -230,14 +230,14 @@ interactionClient.on('commandRunError', async ({context, error}) => {
const message = `Shard #${shard.shardId}: (NOT OK) ${response.statusCode} ${response.request.method}-${response.request.url} (${route.path})`; const message = `Shard #${shard.shardId}: (NOT OK) ${response.statusCode} ${response.request.method}-${response.request.url} (${route.path})`;
console.log(message); console.log(message);
console.log(await response.text()); console.log(await response.text());
await basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_REST_ERROR \`** \`[Shard ${shard.shardId}]\` Shard request error: \`${response.statusCode}\` @ \`${Date.now()}\`\n**\` ${response.request.method} \`** \`${response.request.url}\` (${route.path})\n\`\`\`js\n${await response.text()}\`\`\``) await basecamp(formatErrorMessage(3, "SHARD_REST_ERROR", `\`[Shard ${shard.shardId}]\` Shard request error: \`${response.statusCode}\`\n**\` ${response.request.method} \`** \`${response.request.url}\` (${route.path})\n\`\`\`js\n${await response.text()}\`\`\``));
} }
} }
}); });
cluster.on(ClientEvents.WARN, async ({error}) => { cluster.on(ClientEvents.WARN, async ({error}) => {
if(!process.env.MAINTOWER_URL) { console.warn(error); return; } if(!process.env.MAINTOWER_URL) { console.warn(error); return; }
await basecamp(`<:ico_w2:1086624961025810485>\`[${process.env.HOSTNAME}]\` **\` CLUSTER_WARNING \`** Cluster ${cluster.manager.clusterId} reported warning @ \`${Date.now()}\`:\n\`\`\`${error}\`\`\``) await basecamp(formatErrorMessage(2, "CLUSTER_WARNING", `\`Cluster ${cluster.manager.clusterId} reported warning\`:\n\`\`\`${error}\`\`\``));
}); });
try{ try{

View file

@ -1,3 +1,4 @@
const { icon } = require('#utils/markdown')
const superagent = require('superagent') const superagent = require('superagent')
const MAINTOWER_BASE_URL = process.env.MAINTOWER_URL const MAINTOWER_BASE_URL = process.env.MAINTOWER_URL
@ -5,6 +6,10 @@ const MAINTOWER_BASE_URL = process.env.MAINTOWER_URL
let maintowerClient = "1fepg2wdk-prod" let maintowerClient = "1fepg2wdk-prod"
if(process.env.MAINTOWER_OVERRIDE) maintowerClient = process.env.MAINTOWER_OVERRIDE if(process.env.MAINTOWER_OVERRIDE) maintowerClient = process.env.MAINTOWER_OVERRIDE
module.exports.formatErrorMessage = (sev = 0, code, content) => {
return `${icon("webhook_exclaim_" + parseInt(sev))} \`[${Date.now()}]\` @ \`[${process.env.HOSTNAME}]\` **\` ${code} \`** | ${content}`
}
module.exports.maintower = async function (packages, type){ module.exports.maintower = async function (packages, type){
if(!MAINTOWER_BASE_URL) { console.warn("No maintower url configured."); return; } if(!MAINTOWER_BASE_URL) { console.warn("No maintower url configured."); return; }
try{ try{

View file

@ -1,5 +1,5 @@
const { Permissions, MessageFlags } = require("detritus-client/lib/constants") const { Permissions, MessageFlags } = require("detritus-client/lib/constants")
const { basecamp } = require("../logging") const { basecamp, formatErrorMessage } = require("../logging")
const { COLORS, MESSAGE_BLOCK_REASONS } = require("#constants") const { COLORS, MESSAGE_BLOCK_REASONS } = require("#constants")
const { icon, link } = require("./markdown") const { icon, link } = require("./markdown")
@ -28,7 +28,7 @@ module.exports.editOrReply = function(context, message, disableReference = false
if(context.editOrRespond){ if(context.editOrRespond){
if(context._meta?.replacementMessageId){ if(context._meta?.replacementMessageId){
return context.editMessage(context._meta.replacementMessageId, message).catch((e)=>{ return context.editMessage(context._meta.replacementMessageId, message).catch((e)=>{
basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_MESSAGE_ERROR \`** \`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``, message) basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond:\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message);
}); });
} }
@ -76,13 +76,13 @@ module.exports.editOrReply = function(context, message, disableReference = false
return replacementMessage; return replacementMessage;
} }
basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_MESSAGE_ERROR \`** \`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``, message) basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.command.name}\` failed to respond: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message);
}) })
} }
// Only respond if the command is still available and we have permissions to respond. // Only respond if the command is still available and we have permissions to respond.
if(!context.message.deleted && context.channel.can(Permissions.SEND_MESSAGES)) return context.editOrReply(message).catch((e)=>{ if(!context.message.deleted && context.channel.can(Permissions.SEND_MESSAGES)) return context.editOrReply(message).catch((e)=>{
console.log(e.status) console.log(e.status)
basecamp(`<:ico_w3:1086624963047460874>\`[${process.env.HOSTNAME}]\` **\` SHARD_MESSAGE_ERROR \`** \`[Shard ${context.client.shardId}]\` Command \`${context.message?.content}\` failed to reply: @ \`${Date.now()}\`\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``, message) basecamp(formatErrorMessage(3, "SHARD_MESSAGE_ERROR", `\`[Shard ${context.client.shardId}]\` Command \`${context.message?.content}\` failed to respond:\nGuild: \`${context.guild?.id}\`\nChannel: \`${context.channel?.id}\`\nUser: \`${context.user?.id}\`\`\`\`js\n${e}\`\`\``), message);
}) })
} }