Type Error: "Property "sentryError" does not exist on type 'ILogger'

Ive extended the @sapphire/plugin-logger to add sentry logging, however it is still throwing type errors when I try to use said functions. SentinelLogger.ts
import { container } from '@sapphire/framework';
import { Logger } from '@sapphire/plugin-logger';
import { captureException, captureMessage, Scope } from '@sentry/node';
import { redBright } from 'colorette';

export class SentinelLogger extends Logger {
public infoTag(tag: string, value: unknown): void {
super.info(`[${redBright(tag)}] ${value}`);
}

public sentryMessage(message: string, context?: NonNullable<unknown>): void {
super.error(message);

if (container.isDev) return;

captureMessage(message, (scope): Scope => {
if (context) scope.setExtra('context', context);
return scope;
});
}

public sentryError(error: unknown, { message, context }: { message?: string; context?: NonNullable<unknown> } = {}): void {
message ? super.error(message) : super.error(error);

if (container.isDev) return;

if (error instanceof Error) {
captureException(error, (scope): Scope => {
if (context) scope.setExtras(context);
return scope;
});
}
}
}
import { container } from '@sapphire/framework';
import { Logger } from '@sapphire/plugin-logger';
import { captureException, captureMessage, Scope } from '@sentry/node';
import { redBright } from 'colorette';

export class SentinelLogger extends Logger {
public infoTag(tag: string, value: unknown): void {
super.info(`[${redBright(tag)}] ${value}`);
}

public sentryMessage(message: string, context?: NonNullable<unknown>): void {
super.error(message);

if (container.isDev) return;

captureMessage(message, (scope): Scope => {
if (context) scope.setExtra('context', context);
return scope;
});
}

public sentryError(error: unknown, { message, context }: { message?: string; context?: NonNullable<unknown> } = {}): void {
message ? super.error(message) : super.error(error);

if (container.isDev) return;

if (error instanceof Error) {
captureException(error, (scope): Scope => {
if (context) scope.setExtras(context);
return scope;
});
}
}
}
SentryClient.TS
export class SentinelClient extends SapphireClient {
public constructor() {
super({
logger: {
instance: new SentinelLogger({ level: LogLevel.Debug, join: '\n' })
}
});
}
}
export class SentinelClient extends SapphireClient {
public constructor() {
super({
logger: {
instance: new SentinelLogger({ level: LogLevel.Debug, join: '\n' })
}
});
}
}
Reduced code for clarity Usage:
@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError
})
export class ErrorListener extends Listener<typeof Events.CommandApplicationCommandRegistryError> {
public run(error: Error, command: Command): void {
const { name, location } = command;

this.container.logger.sentryError(error, {
message: `Encountered error while handling the command application command registry for ${name} (${location.full})`,
context: command
});
}
}
@ApplyOptions<Listener.Options>({
event: Events.CommandApplicationCommandRegistryError
})
export class ErrorListener extends Listener<typeof Events.CommandApplicationCommandRegistryError> {
public run(error: Error, command: Command): void {
const { name, location } = command;

this.container.logger.sentryError(error, {
message: `Encountered error while handling the command application command registry for ${name} (${location.full})`,
context: command
});
}
}
Error: https://i.imgur.com/PrA4R7b.png
Imgur
Solution:
If you just want to send all your errors to sentry then you don't need to extend the logger, instead set it up like so: https://github.com/skyra-project/skyra/blob/main/src/Skyra.ts Does that already help possibly?...
GitHub
skyra/src/Skyra.ts at main · skyra-project/skyra
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
Jump to solution
5 Replies
Solution
Favna
Favna4mo ago
If you just want to send all your errors to sentry then you don't need to extend the logger, instead set it up like so: https://github.com/skyra-project/skyra/blob/main/src/Skyra.ts Does that already help possibly?
GitHub
skyra/src/Skyra.ts at main · skyra-project/skyra
A multipurpose Discord Bot designed to carry out most of your server's needs with great performance and stability. - skyra-project/skyra
Favna
Favna4mo ago
If not then the answer is that you need to add module augmentation because nowhere do you tell TS that container.logger is a SentinelLogger
TheeDeer
TheeDeerOP4mo ago
Will do this method instead! Now will this also capture command related errors?
Favna
Favna4mo ago
Yes Well It does for skyra at least Top if my head not 100% sure if we have other stuff in place too Might want to do a general code search for things like sentry and look through skyra's listeners
TheeDeer
TheeDeerOP4mo ago
Looks like listener and tasks are the only two with specific sentry events, thanks.
Want results from more Discord servers?
Add your server