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 new 'WithErrors' constructors #28

Merged
merged 2 commits into from
Apr 24, 2024

Conversation

ktkenny
Copy link
Contributor

@ktkenny ktkenny commented Apr 17, 2024

This PR adds two new constructors which are variations of existing ones. These new functions return an error channel rather than accepting one which allows callers to not need to worry about closing the returned channel themselves.

@ktkenny ktkenny marked this pull request as ready for review April 22, 2024 23:46
@ktkenny ktkenny requested a review from a team April 22, 2024 23:46
aaronfuj
aaronfuj previously approved these changes Apr 23, 2024
func NewSenderFromDevice(d *api.Device, errors chan<- error, cfg *Config) (*Sender, error) {
client := cfg.client()
return cfg.start(client, d, errors)
}

// NewSenderFromDeviceWithErrors returns a Sender and an error channel for an existing Device
Copy link
Contributor

Choose a reason for hiding this comment

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

Would be nice if the other public constructors also got this documentation

lib_test.go Outdated
},
}, config)

assert.NotNil(t, s)
Copy link

Choose a reason for hiding this comment

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

One of my pet peeves is that assert does not stop the test. So if s is nil here the test will fail but will continue to run. And then we'll see a nil pointer access down below when we call s.Send() and that just makes it harder to figure out what's actually broken from the noisier test output.
It's better to use require for assertions where you would want to fail the test and stop immediately.
Eg.: require.NotNil(t, s)

You don't have to change it if you don't want to. Just trying to get the word out.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Funny you mention this. I first learned about require while reading a PR comment of yours from way back and started using it then. I like it a lot. Think I just got a bit lazy here.

I'll sharpen these tests up a bit.

@ktkenny ktkenny merged commit 0ef1e8c into master Apr 24, 2024
4 checks passed
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.

3 participants