Skip to content
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

Issue with button handling in production #1348

Open
victorsmits opened this issue Jan 5, 2025 · 3 comments
Open

Issue with button handling in production #1348

victorsmits opened this issue Jan 5, 2025 · 3 comments
Labels

Comments

@victorsmits
Copy link

What is your question?

For my bot I am using some buttons and in local I encounter no issue at all but in production it seams that the handler broke my app with this error

node:events:498
      throw er; // Unhandled 'error' event
      ^
TypeError: Cannot read properties of null (reading 'isHeadersSent')
    at SentryGlobalFilter.handleUnknownError (/app/node_modules/@nestjs/core/exceptions/base-exception-filter.js:45:29)
    at SentryGlobalFilter.catch (/app/node_modules/@nestjs/core/exceptions/base-exception-filter.js:17:25)
    at SentryGlobalFilter.catch (/app/node_modules/@sentry/nestjs/build/cjs/setup.js:93:23)
    at ExternalExceptionsHandler.invokeCustomFilters (/app/node_modules/@nestjs/core/exceptions/external-exceptions-handler.js:31:32)
    at ExternalExceptionsHandler.next (/app/node_modules/@nestjs/core/exceptions/external-exceptions-handler.js:14:29)
    at MessageComponentDiscovery.contextCallback (/app/node_modules/@nestjs/core/helpers/external-proxy.js:14:42)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
    at emitUnhandledRejectionOrErr (node:events:403:10)
    at process.processTicksAndRejections (node:internal/process/task_queues:84:21)
Node.js v22.2.0
npm notice
npm notice New major version of npm available! 10.7.0 -> 11.0.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.0.0
npm notice To update run: npm install -g [email protected]
npm notice
> [email protected] start:prod
> node dist/main

I do not understand why its happening only in production

@SocketSomeone
Copy link
Member

SocketSomeone commented Jan 6, 2025

Hi, what is isHeadersSent method? Can you create repro?

@victorsmits
Copy link
Author

The global filter come from sentry.io I did not build it.

@SocketSomeone
Copy link
Member

SocketSomeone commented Jan 7, 2025

The global filter come from sentry.io I did not build it.

So, it can be a reason of problem. As I can see it tries to access isHeadersSent method, but Necord doest have HTTP API or something else. So, i think you need extend sentry global filter to correctly process exceptions.

I found that SentryGlobalFilter is inherit from BaseException filter which using this method when error is unknown for sentry global filter

I think you can do something like

@Catch()
class CustomSentryGlobalFilter extends SentryGlobalFilter {
  public constructor(applicationRef?: HttpServer) {
    super(applicationRef);
    this.__SENTRY_INTERNAL__ = true;
    this._logger = new Logger('ExceptionsHandler');
  }

  /**
   * Catches exceptions and reports them to Sentry unless they are expected errors.
   */
  public catch(exception: unknown, host: ArgumentsHost): void {
    if (host.getType<'necord'>() === 'necord') {
      if (exception instanceof Error) {
        this._logger.error(exception.message, exception.stack);
      }

      captureException(exception);
      throw exception;
    }
    
    return super.catch(exception, host);
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants