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

fix: add try catch condition in handlebar template compilation #2317

Merged
merged 10 commits into from
Jan 2, 2023
Merged

fix: add try catch condition in handlebar template compilation #2317

merged 10 commits into from
Jan 2, 2023

Conversation

jainpawan21
Copy link
Member

What change does this PR introduce?

Add try catch condition for handlebars template compilation
Add new detail enum value

Why was this change needed?

Closes #2229

Other information (Screenshots)

Screenshot 2022-12-19 at 5 37 47 PM

Comment on lines 62 to 64
} catch (error) {
return html;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I would actually not return the html here, but throw an ApiError and pass the handlebars content as information there. This error could be watched from the calling function in send-message.email level and than create the execution logs with the actual handlebars error.

Comment on lines 213 to 224
await this.createExecutionDetails.execute(
CreateExecutionDetailsCommand.create({
...CreateExecutionDetailsCommand.getDetailsFromJob(command.job),
detail: DetailEnum.MESSAGE_CONTENT_SYNTAX_ERROR,
source: ExecutionDetailsSourceEnum.INTERNAL,
status: ExecutionDetailsStatusEnum.FAILED,
messageId: message._id,
isTest: false,
isRetry: false,
raw: JSON.stringify(payload),
})
);
Copy link
Contributor

Choose a reason for hiding this comment

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

Here we need to throw an error and don't continue the flow execution since the recipient will get broken template

@@ -209,6 +209,21 @@ export class SendMessageEmail extends SendMessageType {
})
);

if (!html) {
await this.createExecutionDetails.execute(
Copy link
Contributor

Choose a reason for hiding this comment

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

Combining with my comment from above regarding catching in the actual send message usecase and not compile template. We need to add this execution detail to all channels, so maybe consider moving this catching to one level above?

@davidsoderberg
Copy link
Contributor

Fix @scopsy comments and I think it is ready to merge :)

@jainpawan21
Copy link
Member Author

jainpawan21 commented Dec 27, 2022

@scopsy shifted try catch one level above and added handlebar error in execution details
Screenshot 2022-12-27 at 6 40 29 PM

@ainouzgali
Copy link
Contributor

Hi @jainpawan21 , correct me if I'm wrong, but this still won't apply to the other channels, right? Like sms, in app, push etc

@jainpawan21
Copy link
Member Author

jainpawan21 commented Dec 27, 2022

Hi @jainpawan21 , correct me if I'm wrong, but this still won't apply to the other channels, right? Like sms, in app, push etc

Yes, You are right, it will handle only email syntax error

@ainouzgali
Copy link
Contributor

I've actually been working on something similar before I noticed your PR 🙈 Would you mind if I join you on this one and push some of my changes? @jainpawan21

@jainpawan21
Copy link
Member Author

I've actually been working on something similar before I noticed your PR 🙈 Would you mind if I join you on this one and push some of my changes? @jainpawan21

Yes sure Gali

@ainouzgali
Copy link
Contributor

@jainpawan21 I added the try catch to also be on the first render&compile (not only on the html). And also to wrap the compiles for subject, preheader, cta etc . Also changed it for all channels.
Pawan, please let me know what you think :)

@scopsy
Copy link
Contributor

scopsy commented Jan 2, 2023

@ainouzgali what do you think also adding a validation on the client side? So we can even skip the server request if the compile message fails on the client?

@ainouzgali
Copy link
Contributor

@scopsy Yes, I definitely want that. I've started looking into that, but it is not as straight forward. I will continue at the next cool down. Or, we could open it for the community, in case someone will be available to help on this.
Also. I wouldn't do it on the client, but rather on save/update of template.

@ainouzgali ainouzgali merged commit 9c331e3 into novuhq:next Jan 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Email failing when template have syntax error
4 participants