You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since watchbot 4.13.0 it is possible to use watchbot with a fifo queue and the message parsing was changed to accomodate this. This broke allowing empty sns subjects, which was originally introduced in #240.
// If the Watchbot instance uses a regular SQS queue, sqsMessage
// will have come from an SNS topic, so the body will be a JSON object
// with Message and Subject properties.
//
// If the SQS message is for a FIFO queue, it did not come from SNS
// so will not have the same structure and might not be JSON
// parseable. If it is, we'll parse it; if not, we'll just pass it on.
We try to see if the message is parseable here:
try {
const parsedBody = JSON.parse(sqsMessage.Body);
if (parsedBody.Subject) {
envMessage = parsedBody.Message;
envSubject = parsedBody.Subject;
}
} catch (error) {
// JSON-parsing failure means we can leave the body as it is.
}
However, this will fail if the message does not contain a subject. The subject is not a required key, and so even a standard sns message that came through a non-fifo queue but for some reason does not contain a Subject key will not be parsed as expected.
I ran into this this week with two separate repositories while upgrading them to the latest watchbot version - in one case, I was sending an SNS message via the console and did not specify a Subject (again, not a required parameter), and in another case, I was sending the message using code like this:
sns
.publish({
Message: "my message",
TopicArn: "arn:aws:sns..."
})
... without specifying a Subject.
Next actions
I could imagine two possible fixes, but I need some more context on whether those might break something else 🤔
Explicitly check that option.fifo === true in the try statement - since if I understand correctly, this is only needed for fifo queues.
remove the if parsedBody.Subject clause and always assign message to parseBody.Message if parsedBody.Message exists and the json parsing was successful
cc @mapbox/platform
The text was updated successfully, but these errors were encountered:
Since watchbot 4.13.0 it is possible to use watchbot with a fifo queue and the message parsing was changed to accomodate this. This broke allowing empty sns subjects, which was originally introduced in #240.
From lib/message.js:
We try to see if the message is parseable here:
However, this will fail if the message does not contain a subject. The
subject
is not a required key, and so even a standard sns message that came through a non-fifo queue but for some reason does not contain aSubject
key will not be parsed as expected.I ran into this this week with two separate repositories while upgrading them to the latest watchbot version - in one case, I was sending an SNS message via the console and did not specify a Subject (again, not a required parameter), and in another case, I was sending the message using code like this:
... without specifying a
Subject
.Next actions
I could imagine two possible fixes, but I need some more context on whether those might break something else 🤔
option.fifo === true
in thetry
statement - since if I understand correctly, this is only needed for fifo queues.if parsedBody.Subject
clause and always assign message toparseBody.Message
ifparsedBody.Message
exists and the json parsing was successfulcc @mapbox/platform
The text was updated successfully, but these errors were encountered: