Skip to content

Fix/nestjs cron issues #16792

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

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

0xbad0c0d3
Copy link
Contributor

Nestjs sync task has the same issue as async tasks - they don't care about exceptions because nestjs @Cron() decorator automatically wraps it to try-catch block and logs an error. That's why we should capture exception in our @SentryCron() decorator.
P.S. I didn't test, but, most probably, fixes also #16749

  • If you've added code that should be tested, please add tests.
  • Ensure your code lints and the test suite passes (yarn lint) & (yarn test).

cod1k added 3 commits July 2, 2025 18:49
Add a command to delete the Sentry-related cache during the E2E test setup process. This ensures a clean testing environment and prevents potential issues caused by stale cache. This is why running tests locally after any change might be wrong. Not sure this is the best solution, or no. But, at least results are constant now
Introduced a new `testSyncCronError` method to handle sync cron job errors and updated the async method for clarity. Updated tests to cover both async and sync cron scenarios, ensuring proper error handling and reporting to Sentry.
Added error capturing for both synchronous and asynchronous exceptions in monitored methods. Incorporated `isThenable` checks to handle promises properly, ensuring robust error tracking with Sentry in both cases.
Copy link
Member

@andreiborza andreiborza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, thank you for contributing this!

cc @chargome

@@ -66,6 +66,7 @@ async function run(): Promise<void> {
}

await asyncExec('pnpm clean:test-applications', { env, cwd: __dirname });
await asyncExec('pnpm cache delete "@sentry/*"', { env, cwd: __dirname });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m: Is this necessary? Did you run into issues without it? I think we should not add this in this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest - no, it is not necessary to be here in this PR. But yes, you are going to run into an issue without this. The issue is that if you are doing any changes to any package and want to run e2e tests locally with yarn workspace @sentry-internal/e2e-tests test:run app-name your very first test will be executed as expected. But any other changes are not going to be reflected by pnpm install because of the cache.

@andreiborza andreiborza requested a review from chargome July 2, 2025 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants