From 1dba107b0b1ddeed673b950ab04ea25a2d8dc60f Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 14 Apr 2023 10:48:42 +0200 Subject: [PATCH 1/2] fix(gatsby): Don't crash build when auth token is missing --- packages/gatsby/gatsby-node.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 3ff28720a873..98265c413676 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -46,10 +46,15 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { // Handle sentry-cli configuration errors when the user has not done it not to break // the build. errorHandler(err, invokeErr) { - const { message } = err; + const message = err.message && err.message.toLowerCase() || ''; if (message.includes('organization slug is required') || message.includes('project slug is required')) { return; } + if (message.includes('authentication credentials were not provided')) { + // eslint-disable-next-line no-console + console.warn('Sentry Logger [Warn]: Cannot upload source maps due to missing SENTRY_AUTH_TOKEN env variable.') + return; + } invokeErr(err); }, }), From fa34c18a5975437ca395d35b3f02d1a6bdc8ab57 Mon Sep 17 00:00:00 2001 From: Lukas Stracke Date: Fri, 14 Apr 2023 11:47:51 +0200 Subject: [PATCH 2/2] review suggestions --- packages/gatsby/gatsby-node.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/gatsby/gatsby-node.js b/packages/gatsby/gatsby-node.js index 98265c413676..e7e0776fa26f 100644 --- a/packages/gatsby/gatsby-node.js +++ b/packages/gatsby/gatsby-node.js @@ -48,11 +48,13 @@ exports.onCreateWebpackConfig = ({ plugins, getConfig, actions }) => { errorHandler(err, invokeErr) { const message = err.message && err.message.toLowerCase() || ''; if (message.includes('organization slug is required') || message.includes('project slug is required')) { + // eslint-disable-next-line no-console + console.log('Sentry [Info]: Not uploading source maps due to missing SENTRY_ORG and SENTRY_PROJECT env variables.') return; } if (message.includes('authentication credentials were not provided')) { // eslint-disable-next-line no-console - console.warn('Sentry Logger [Warn]: Cannot upload source maps due to missing SENTRY_AUTH_TOKEN env variable.') + console.warn('Sentry [Warn]: Cannot upload source maps due to missing SENTRY_AUTH_TOKEN env variable.') return; } invokeErr(err); @@ -98,7 +100,7 @@ function injectSentryConfig(config, configFile) { } else { // eslint-disable-next-line no-console console.error( - `Sentry Logger [Error]: Could not inject SDK initialization code into ${prop}, unexpected format: `, + `Sentry [Error]: Could not inject SDK initialization code into ${prop}, unexpected format: `, typeof value, ); }