fix(bulk-publish): add null guard on asset.publish_details before forEach#260
fix(bulk-publish): add null guard on asset.publish_details before forEach#260aniket-shikhare-cstk wants to merge 2 commits into
Conversation
…Each Assets loaded from --data-dir backup may not have a publish_details field if they were never published. The optional chain only guarded `asset`, not `publish_details`, causing a TypeError in displayAssetsDetails().
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
Consider reviewing these vulnerabilities when fixes become available. |
There was a problem hiding this comment.
Pull request overview
This PR prevents a runtime crash in the contentstack-bulk-publish plugin when rendering asset publish details after a bulk publish, specifically when assets loaded from --data-dir backups don’t have publish_details.
Changes:
- Adds an additional null/undefined guard when iterating over
asset.publish_detailsindisplayAssetsDetails()to avoidTypeErrorin post-publish logging.
Comments suppressed due to low confidence (1)
packages/contentstack-bulk-publish/src/consumer/publish.js:68
publish_details?.forEach(...)only guardsnull/undefined. Ifpublish_detailsis present but not an array (e.g.,{}from a backup/transform), this will still throw becauseforEachis not a function.displayEntriesDetails()in this same file already uses anArray.isArray(...)guard; applying the same pattern here avoids the remaining crash case and keeps the code consistent.
asset?.publish_details?.forEach((pd) => {
if (Object.keys(mapping).includes(pd.environment)) {
console.log(
chalk.green(
`Asset UID: '${asset.uid}'${pd.version ? `, Version: '${pd.version}'` : ''}${
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…sets.js setConfig() assigned to `config` at module scope but the variable was never declared, causing a ReferenceError on any cm:assets:publish run that goes through the data-dir flow.
🔒 Security Scan Results
⏱️ SLA Breach Summary
ℹ️ Vulnerabilities Without Available Fixes (Informational Only)The following vulnerabilities were detected but do not have fixes available (no upgrade or patch). These are excluded from failure thresholds:
Consider reviewing these vulnerabilities when fixes become available. |
Summary
displayAssetsDetails()inpublish.jsiteratedasset?.publish_details.forEach(...)where the optional chain only guardedasset, notpublish_details--data-dirbackup may not have apublish_detailsfield (e.g. assets never previously published), causing aTypeError: Cannot read properties of undefined (reading 'forEach')asset?.publish_details?.forEach(...)— consistent with the safeArray.isArray(entry?.publish_details)guard already used for entries in the same fileRoot Cause
The crash occurred in the error path (
catchblock at line 393) after the bulk publish API call had already been dispatched successfully. The assets were sent for publish, but the post-publish display/logging function crashed when encountering assets without apublish_detailsfield.Test plan
cm:assets:publishwith a--data-dirbackup that contains assets with no priorpublish_detailsTypeErrorin output and CLI exits cleanly