-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
Update getLastJobRunTimestamp to return null if job properties empty #22563
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
base: main
Are you sure you want to change the base?
Conversation
In production, I am seeing this error: begin.toISOString is not a function at #fetchEvents (/ghost/node_modules/@tryghost/email-analytics-service/lib/EmailAnalyticsService.js:292:64) at EmailAnalyticsService.fetchMissing (/ghost/node_modules/@tryghost/email-analytics-service/lib/EmailAnalyticsService.js:184:39) at async EmailAnalyticsServiceWrapper.fetchMissing (/ghost/core/server/services/email-analytics/EmailAnalyticsServiceWrapper.js:90:29) It seems to stem from this function returning neither a Date nor a null. If it were null, we would likely see this: TypeError: can't access property "toISOString" of null And, it can't be returning a Date because toISOString() is defined on Date. I think the problem is that `jobData.finished_at` and `jobData.started_at` are returning something else, possibly an empty string or a falsey value. I think the original programmer intended to handle this because it's using the boolean OR rather than the null coalescing operator (which treats "" as truthy). However, if neither of them are set, this function is returning something else. This then causes a problem for `getLastMissingEventTimestamp`, which uses null coalescing rather than boolean OR; therefore it is returning something incorrect, for the fetchEvents function to trip up over. I don't think I'm the first person to see this issue, I found [this post](https://forum.ghost.org/t/issue-with-routes-yaml/54607/3) and I suspect given that this happens in the logs but is otherwise not visible, the error might be more widespread.
WalkthroughThe change updates the Assessment against linked issues
Tip ⚡🧪 Multi-step agentic review comment chat (experimental)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🔇 Additional comments (1)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
As mentioned on the issue, in order to be able to fix this, we need to track down the repro case exactly and get a test in place :) |
In production, I am seeing this error:
It seems to stem from this function returning neither a Date nor a null. If it were null, we would likely see this:
TypeError: can't access property "toISOString" of null
. And, it can't be returning aDate
becausetoISOString()
is defined onDate
. I can replicate this error message with the following code:const begin = ""; begin.toISOString()
.I think the problem is likely that
jobData.finished_at
andjobData.started_at
are returning something else, likely an empty string or another falsey value. I think the original programmer intended to handle this because it's using the boolean OR (||
) rather than the null coalescing operator (which would treat "" as truthy). In this case I think neither of them are set, so this function is returning something else.This then causes a problem for
getLastMissingEventTimestamp
, which uses null coalescing rather than boolean OR; therefore it is returning something incorrect, for the#fetchEvents
function to trip up over.I don't think I'm the first person to see this issue, I found this post and I suspect given that this happens in the logs but is otherwise not visible, the error might be more widespread.
Fixes #22561