Skip to content

fix(gatsby): Don't crash build when auth token is missing #7858

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

Merged
merged 2 commits into from
Apr 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions packages/gatsby/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

l: Do we maybe wanna add a similar error message right here as a quick win?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I wrote in the PR, there's an argument to be made that if these env vars are not specified, users don't want to upload source maps and hence there should be no warning. But let's just display a "info" level message here that we're not gonna upload source maps in case these variables aren't set.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry! I skipped over that. I think printing a message is good here since having source maps is such a productivity win - I think we wanna tell users about it :D

// 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 [Warn]: Cannot upload source maps due to missing SENTRY_AUTH_TOKEN env variable.')
return;
}
invokeErr(err);
Expand Down Expand Up @@ -93,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,
);
}
Expand Down