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

feat(connect): use extracted connection logic from mongosh MONGOSH-1080 #390

Merged

Conversation

alenakhineika
Copy link
Contributor

@alenakhineika alenakhineika commented Feb 7, 2022

Description

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

src/test/suite/connectionController.test.ts Show resolved Hide resolved
message: string;
stack?: string;
} => {
if (err instanceof Error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you want to check whether something is a built-in Error object, this is better:

Suggested change
if (err instanceof Error) {
if (Object.prototype.toString.call(err) === '[object Error]') {

since instanceof is not a reliable brand check in JS:

> vm.runInNewContext('new Error("banana")')
Error: banana
    at evalmachine.<anonymous>:1:1
    [ rest of stack ]
> vm.runInNewContext('new Error("banana")') instanceof Error
false

or alternatively I’d be more specific and just test whether the actual properties you’re looking for are present:

Suggested change
if (err instanceof Error) {
if (typeof err?.name === 'string' && typeof err?.message === 'string' && typeof err?.stack === 'string') {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nice!! thank you for the suggestion! ❤️

@alenakhineika alenakhineika merged commit cbab069 into main Feb 8, 2022
@alenakhineika alenakhineika deleted the MONGOSH-1080-use-extracted-connection-logic-from-mongosh branch February 8, 2022 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants