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

add tri-state verification to mongodb detector #1575

Merged
merged 10 commits into from
Jul 31, 2023
Merged

Conversation

rosecodym
Copy link
Collaborator

No description provided.

@rosecodym rosecodym marked this pull request as ready for review July 28, 2023 19:19
Comment on lines -56 to -60
defer func() {
if err := client.Disconnect(ctx); err != nil {
return
}
}()
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@ahrav i think this was just discarding the result of client.Disconnect so i simplified it a bit when i moved it, but give a shout if the new version looks wrong

Copy link
Collaborator

Choose a reason for hiding this comment

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

looks good!

@rosecodym rosecodym requested review from ahrav and a team July 28, 2023 19:20
Comment on lines -56 to -60
defer func() {
if err := client.Disconnect(ctx); err != nil {
return
}
}()
Copy link
Collaborator

Choose a reason for hiding this comment

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

looks good!

}
results = append(results, s1)
}

return results, nil
}

func isErrDeterminate(err error) bool {
Copy link
Collaborator

@ahrav ahrav Jul 31, 2023

Choose a reason for hiding this comment

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

suggestion: I think you can simplify this with:

if e, ok := err.(topology.ConnectionError); ok {
    _, ok = e.Unwrap().(*auth.Error)
    return ok
}
return false

or i guess if we want to use the errors pkg:

func isErrDeterminate(err error) bool {
    var connErr topology.ConnectionError
    if errors.As(err, &connErr) {
        var authErr *auth.Error
	return errors.As(connErr.Unwrap(), &authErr)
    }
    return false
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

i actually specifically wrote this not to be as terse as possible, but to make it easy to extend with other error cases in the future. do you find it hard to read as it is?

Copy link
Collaborator

Choose a reason for hiding this comment

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

ahh okay, i think that makes sense. I sorta had the feeling, but wasn't sure. If we leave the switches might be worth adding the default case to each, no mandatory though. One of the the go linters happens to yell at me when i have a switch with no default. 🤷

if err != nil {
return err
}
defer func() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: since we are ignoring the err here anyways we can inline it:
defer client.Disconnect(ctx)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

huh, i could have sworn the linter didn't let me do that...

Copy link
Collaborator

Choose a reason for hiding this comment

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

might've complained that you are ignoring the err i suppose.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah golangci-lint is not about this

@rosecodym rosecodym merged commit 7d2f126 into main Jul 31, 2023
9 checks passed
@rosecodym rosecodym deleted the tri-state-mongodb branch July 31, 2023 22:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants