Skip to content

refactor: capture only specific errors #487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/Commands/RunRepeater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
} from '../Repeater';
import { Arguments, Argv, CommandModule } from 'yargs';
import { Lifecycle } from 'tsyringe';
import { captureException } from '@sentry/node';
import { normalize } from 'path';

export class RunRepeater implements CommandModule {
Expand Down Expand Up @@ -244,12 +245,16 @@ export class RunRepeater implements CommandModule {

if (args.remove) {
await repeaterLauncher.uninstall();
process.exit(0);
process.exitCode = 0;

return;
}

if (args.daemon) {
await repeaterLauncher.install();
process.exit(0);
process.exitCode = 0;

return;
}

try {
Expand All @@ -262,6 +267,7 @@ export class RunRepeater implements CommandModule {

await repeaterLauncher.run(args.id as string, args.run as boolean);
} catch (e) {
captureException(e);
logger.error(e);
await repeaterLauncher.close();
process.exitCode = 1;
Expand Down
4 changes: 3 additions & 1 deletion src/Repeater/DefaultRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { RepeaterCommandHub } from './RepeaterCommandHub';
import { RuntimeDetector } from './RuntimeDetector';
import { gt } from 'semver';
import chalk from 'chalk';
import { captureException } from '@sentry/node';
import { delay, inject, injectable } from 'tsyringe';
import Timer = NodeJS.Timer;

Expand All @@ -40,9 +41,10 @@ export class DefaultRepeaterLauncher implements RepeaterLauncher {
@inject(delay(() => CliInfo)) private readonly info: CliInfo
) {
this.bus.onReconnectionFailure(async (e: Error) => {
captureException(e);
logger.error(e);
await this.close();
process.exit(1);
process.exitCode = 1;
});
}

Expand Down
10 changes: 7 additions & 3 deletions src/Repeater/DefaultRepeaterServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { inject, injectable } from 'tsyringe';
import io, { Socket } from 'socket.io-client';
import parser from 'socket.io-msgpack-parser';
import { SocksProxyAgent } from 'socks-proxy-agent';
import { captureException, captureMessage } from '@sentry/node';
import { once } from 'events';
import { parse } from 'url';
import Timer = NodeJS.Timer;
Expand Down Expand Up @@ -170,9 +171,11 @@ export class DefaultRepeaterServer implements RepeaterServer {
public errorOccurred(
handler: (event: RepeaterServerErrorEvent) => void | Promise<void>
): void {
this.socket.on('error', (payload, callback) =>
this.processEventHandler('error', payload, handler, callback)
);
this.socket.on('error', (payload, callback) => {
captureMessage(payload.message);

return this.processEventHandler('error', payload, handler, callback);
});
}

public reconnectionAttempted(
Expand Down Expand Up @@ -220,6 +223,7 @@ export class DefaultRepeaterServer implements RepeaterServer {

callback(response);
} catch (error) {
captureException(error);
logger.debug(
'Error processing event "%s" with the following payload: %s. Details: %s',
event,
Expand Down
4 changes: 3 additions & 1 deletion src/Repeater/ServerRepeaterLauncher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { CliInfo } from '../Config';
import { RepeaterCommandHub } from './RepeaterCommandHub';
import { delay, inject, injectable } from 'tsyringe';
import chalk from 'chalk';
import { captureException } from '@sentry/node';

@injectable()
export class ServerRepeaterLauncher implements RepeaterLauncher {
Expand Down Expand Up @@ -161,9 +162,10 @@ export class ServerRepeaterLauncher implements RepeaterLauncher {
}

private reconnectionFailed({ error }: RepeaterServerReconnectionFailedEvent) {
captureException(error);
logger.error(error);
this.close().catch(logger.error);
process.exit(1);
process.exitCode = 1;
}

private async testingNetwork(event: RepeaterServerNetworkTestEvent) {
Expand Down
13 changes: 0 additions & 13 deletions src/Utils/Logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@ export class Logger {
return;
}

const captureContext = {
contexts: {
errorArgs: Object.fromEntries([messageOrArg, ...args].entries())
}
};
let message: string;

if (typeof errorOrMessage === 'string') {
Expand All @@ -54,15 +49,7 @@ export class Logger {
}

message = errorOrMessage;
const formattedMessage = format(message, ...args);

captureMessage(formattedMessage, {
...captureContext,
level: 'error'
});
} else {
captureException(errorOrMessage, captureContext);

message = messageOrArg ?? errorOrMessage.message;
}

Expand Down