Skip to content

fix(nextjs): Add better error messages for missing params during next build #7434

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 1 commit into from
Mar 13, 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
96 changes: 74 additions & 22 deletions packages/nextjs/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -630,32 +630,80 @@ export function getWebpackPluginOptions(
...defaultPluginOptions,
...userPluginOptions,
errorHandler(err, invokeErr, compilation) {
// Hardcoded way to check for missing auth token until we have a better way of doing this.
if (err && err.message.includes('Authentication credentials were not provided.')) {
const warningPrefix = `${chalk.yellow('warn')} -`;

let msg;

if (process.env.VERCEL) {
msg = `To fix this, use Sentry's Vercel integration to automatically set the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable: https://vercel.com/integrations/sentry`;
} else {
msg =
'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
`After generating a Sentry auth token, set it via the ${chalk.bold.cyan(
if (err) {
const errorMessagePrefix = `${chalk.red('error')} -`;

// Hardcoded way to check for missing auth token until we have a better way of doing this.
if (err.message.includes('Authentication credentials were not provided.')) {
let msg;

if (process.env.VERCEL) {
msg = `To fix this, use Sentry's Vercel integration to automatically set the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable during the build.`;
)} environment variable: https://vercel.com/integrations/sentry`;
} else {
msg =
'You can find information on how to generate a Sentry auth token here: https://docs.sentry.io/api/auth/\n' +
`After generating a Sentry auth token, set it via the ${chalk.bold.cyan(
'SENTRY_AUTH_TOKEN',
)} environment variable during the build.`;
}

// eslint-disable-next-line no-console
console.error(
`${errorMessagePrefix} ${chalk.bold(
'No Sentry auth token configured.',
)} Source maps will not be uploaded.\n${msg}\n`,
);

return;
}

// eslint-disable-next-line no-console
console.error(
`${warningPrefix} ${chalk.bold(
'No Sentry auth token configured.',
)} Source maps will not be uploaded.\n${msg}\n`,
);
// Hardcoded way to check for missing org slug until we have a better way of doing this.
if (err.message.includes('An organization slug is required')) {
let msg;
if (process.env.VERCEL) {
msg = `To fix this, use Sentry's Vercel integration to automatically set the ${chalk.bold.cyan(
'SENTRY_ORG',
)} environment variable: https://vercel.com/integrations/sentry`;
} else {
msg = `To fix this, set the ${chalk.bold.cyan(
'SENTRY_ORG',
)} environment variable to the to your organization slug during the build.`;
}

// eslint-disable-next-line no-console
console.error(
`${errorMessagePrefix} ${chalk.bold(
'No Sentry organization slug configured.',
)} Source maps will not be uploaded.\n${msg}\n`,
);

return;
}

return;
// Hardcoded way to check for missing project slug until we have a better way of doing this.
if (err.message.includes('A project slug is required')) {
let msg;
if (process.env.VERCEL) {
msg = `To fix this, use Sentry's Vercel integration to automatically set the ${chalk.bold.cyan(
'SENTRY_PROJECT',
)} environment variable: https://vercel.com/integrations/sentry`;
} else {
msg = `To fix this, set the ${chalk.bold.cyan(
'SENTRY_PROJECT',
)} environment variable to the name of your Sentry project during the build.`;
}

// eslint-disable-next-line no-console
console.error(
`${errorMessagePrefix} ${chalk.bold(
'No Sentry project slug configured.',
)} Source maps will not be uploaded.\n${msg}\n`,
);

return;
}
}

if (userPluginOptions.errorHandler) {
Expand All @@ -679,6 +727,10 @@ function shouldEnableWebpackPlugin(buildContext: BuildContext, userSentryOptions
// with the `--ignore-scripts` option, this will be blocked and the missing binary will cause an error when users
// try to build their apps.
if (!SentryWebpackPlugin.cliBinaryExists()) {
// eslint-disable-next-line no-console
console.error(
`${chalk.red('error')} - ${chalk.bold('Sentry CLI binary not found.')} Source maps will not be uploaded.\n`,
);
return false;
}

Expand Down