Skip to content
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

fix: only show error detail when error.original is defined #1241

Merged
merged 2 commits into from
Jan 25, 2023

Conversation

Rochet2
Copy link
Contributor

@Rochet2 Rochet2 commented Jan 25, 2023

Pull Request check-list

Please make sure to review and check all of these items:

  • Does npm run test pass with this change (including linting)?
  • Does the description below contain a link to an existing issue (Closes #[issue]) or a description of the issue you are solving?
  • Have you added new tests to prevent regressions?
  • Is a documentation update included (if this change modifies existing APIs, or introduces new ones)?

Description of change

Using "sequelize-cli": "6.5.2",

When up handler of a migration throws a custom error.

throw new Error(
  `foobar`,
);

The cli throws the following error

TypeError: Cannot read properties of undefined (reading 'detail')
    at Object.error (/myproject/node_modules/sequelize-cli/lib/helpers/view-helper.js:31:24)
    at /myproject/node_modules/sequelize-cli/lib/commands/migrate.js:68:39
    at async exports.handler (/myproject/node_modules/sequelize-cli/lib/commands/migrate.js:27:7)

The error originates from this line:

    if (error.original.detail) { // this causes the error because original is null/undefined
      console.error(`${_cliColor.default.red('ERROR DETAIL:')} ${error.original.detail}`);
    }

In this PR we change the IF condition to check if the original field is set so the error will not occur.

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Thanks for this PR!

Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Sorry, approved too quickly. We still support Node 10 which does not have the optional chaining

src/helpers/view-helper.js Outdated Show resolved Hide resolved
Co-authored-by: Rik Smale <13023439+WikiRik@users.noreply.github.com>
@WikiRik WikiRik changed the title Fix condition when error does not contain original fix: only show error detail when error.original is defined Jan 25, 2023
Copy link
Member

@WikiRik WikiRik left a comment

Choose a reason for hiding this comment

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

Thanks for the quick update!

@WikiRik WikiRik merged commit 8ba4748 into sequelize:main Jan 25, 2023
@Rochet2 Rochet2 deleted the fix-error-report branch January 25, 2023 09:43
@github-actions
Copy link

🎉 This PR is included in version 6.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants