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

feat: catch errors of wrong use of handlebars #5527

Merged
merged 4 commits into from
May 8, 2024

Conversation

ainouzgali
Copy link
Contributor

@ainouzgali ainouzgali commented May 8, 2024

What changed? Why was the change needed?

For compile email template, there was no catch block for wrong use of handlebars syntax which resulted in

  1. A lot of sentry errors that only creates clutter
  2. Uninformative message for the user (showed Internal server error)

I added the try-catch on the actual template compilation - so we won't miss adding it in each place we are using that usecase.

Sentry links:
1, 2, 3, 4, 5, 6

Screenshots

Expand for optional sections

Related enterprise PR

Special notes for your reviewer

Copy link

linear bot commented May 8, 2024

Copy link

netlify bot commented May 8, 2024

Deploy Preview for novu-design ready!

Name Link
🔨 Latest commit 19c4757
🔍 Latest deploy log https://app.netlify.com/sites/novu-design/deploys/663ba861867bcb0008a5f70e
😎 Deploy Preview https://deploy-preview-5527--novu-design.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented May 8, 2024

Deploy Preview for dev-web-novu ready!

Name Link
🔨 Latest commit 19c4757
🔍 Latest deploy log https://app.netlify.com/sites/dev-web-novu/deploys/663ba8613d35d7000802b231
😎 Deploy Preview https://deploy-preview-5527--dev-web-novu.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@ainouzgali ainouzgali requested review from a team, davidsoderberg and antonjoel82 and removed request for a team May 8, 2024 15:06
const template = Handlebars.compile(templateContent);

result = template(command.data, {});
} catch (e: any) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
} catch (e: any) {
} catch (e: unknown) {

Better TS ;)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately, it creates a ts error for e.message 😬

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At the moment, thats how all catch errors are typed in the project

Copy link
Contributor

Choose a reason for hiding this comment

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

@ainouzgali You can use checkIsResponseError as a type-guard here! TypeScript began recommending unknown as the type for catch in TS 4.4

Copy link
Contributor

@antonjoel82 antonjoel82 May 8, 2024

Choose a reason for hiding this comment

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

@BiswaViraj Side note: I would suggest that we reserve Request changes for blocking problems (like issue or important chores) 🙂 -- this is probably more of a nitpick until we put it into a coding style guide

(But agree with commenting on it so we have fewer places to change later 🙌 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool. Didn't know about it. Thanks!

@ainouzgali ainouzgali requested a review from BiswaViraj May 8, 2024 15:29
Copy link
Contributor

@antonjoel82 antonjoel82 left a comment

Choose a reason for hiding this comment

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

🙌

@ainouzgali ainouzgali dismissed BiswaViraj’s stale review May 8, 2024 16:39

I really want to merge it before the next scheduled tests ❤️

@ainouzgali ainouzgali merged commit 8c2c809 into next May 8, 2024
27 checks passed
@ainouzgali ainouzgali deleted the nv-3772-missing-catch-for-email-compile branch May 8, 2024 16:39
SokratisVidros pushed a commit that referenced this pull request May 13, 2024
* feat: catch errors of wrong use of handlebars

* feat: use type guard for error
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.

3 participants