From dac2b73ec57077a4a74baa652eff6b3cabf1c1d3 Mon Sep 17 00:00:00 2001 From: Kyle Mathews Date: Wed, 8 Sep 2021 08:12:50 -0700 Subject: [PATCH] fix(gatsby-source-drupal): validate webhook bodies & updated node data (#33079) * fix(gatsby-source-drupal): validate webhook bodies & updated node data Fix some errors we've seen on Drupal sites from updates coming. Ideally we iron out too whatever is triggering malformed/missing updates from coming in. This will at least not break builds + give us some more info to track down the deeper issue. * Clarify warning --- packages/gatsby-source-drupal/src/gatsby-node.js | 14 ++++++++++++++ packages/gatsby-source-drupal/src/utils.js | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.js b/packages/gatsby-source-drupal/src/gatsby-node.js index 2703a0c5d92d6..53a77d41e5da9 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.js +++ b/packages/gatsby-source-drupal/src/gatsby-node.js @@ -146,6 +146,20 @@ exports.sourceNodes = async ( changesActivity.end() return } + + if (!action || !data) { + reporter.warn( + `The webhook body was malformed + +${JSON.stringify(webhookBody, null, 4)} + + ` + ) + + changesActivity.end() + return + } + if (action === `delete`) { let nodesToDelete = data if (!Array.isArray(data)) { diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.js index 8e8a42fced0ab..7cdd67ef4e928 100644 --- a/packages/gatsby-source-drupal/src/utils.js +++ b/packages/gatsby-source-drupal/src/utils.js @@ -196,6 +196,17 @@ const handleWebhookUpdate = async ( }, pluginOptions = {} ) => { + if (!nodeToUpdate || !nodeToUpdate.attributes) { + reporter.warn( + `The updated node was empty or is missing the required attributes field. The fact you're seeing this warning means there's probably a bug in how we're creating and processing updates from Drupal. + +${JSON.stringify(nodeToUpdate, null, 4)} + ` + ) + + return + } + const { createNode } = actions const newNode = nodeFromData(