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

refactor: make NewClient return an error #674

Merged
merged 1 commit into from Aug 22, 2023

Conversation

sruehl
Copy link
Contributor

@sruehl sruehl commented Aug 21, 2023

This PR addresses the TODO Note: Starting with v0.5 this function will return an error. and let NewClient return an error.

Note on the PR: I use github.com/stretchr/testify for error assertion with seems IMHO pretty standard in the go projects I worked with. If this is unwanted I could rework this.

resolves #621

@sruehl
Copy link
Contributor Author

sruehl commented Aug 21, 2023

@magiconair I worked on a TODO you defined in source. Not sure if there is a ticket for that. If I find it I link it here. (Edit: found it and linked)

Copy link
Member

@magiconair magiconair left a comment

Choose a reason for hiding this comment

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

Thank you! I've missed that part with the move to v0.5. Please do not check the error for the c.Close() method everywhere since we cannot do anything with that error anyway. There is no way to recover. We just have this in the signature to be consistent.

As for testify. I went down that route before and decided against this since it would introduce the third testing framework into the code base. Yes, it is more convenient but it doesn't justify the cost of having different code styles in different parts of the code base. So please refactor this to look like the rest (i.e. got,want style and maybe use verify.Values)

client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
config_test.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
@sruehl
Copy link
Contributor Author

sruehl commented Aug 21, 2023

Oh and before I forget, take a closer look (@magiconair) what I did with errors. So I collect the errors there and return them with join. Could also be done via early exit. Also I wrap errors with %w. Maybe this is unwanted too.

@magiconair
Copy link
Member

I'll have a look. As a guiding principle I prefer consistency when we make changes like this. I'm OK with changing direction but then let's do it all over the place. And in a separate PR.

client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
client_test.go Outdated Show resolved Hide resolved
@sruehl sruehl force-pushed the refactor/error_handling branch 4 times, most recently from fbb016c to 88cd5e9 Compare August 21, 2023 11:31
@sruehl
Copy link
Contributor Author

sruehl commented Aug 21, 2023

I'll have a look. As a guiding principle I prefer consistency when we make changes like this. I'm OK with changing direction but then let's do it all over the place. And in a separate PR.

Clarifying question on that: I assumed that comment was related to wrapping with %w. Should I switch from errrors join to early exit too?

@sruehl sruehl requested a review from magiconair August 21, 2023 11:58
Copy link
Member

@magiconair magiconair left a comment

Choose a reason for hiding this comment

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

Final nitpick about a variable name but then this LGTM.

client.go Outdated Show resolved Hide resolved
client.go Outdated Show resolved Hide resolved
config.go Outdated Show resolved Hide resolved
@magiconair
Copy link
Member

As an aside: I've done the force-push update as well earlier in my career and while that keeps the commit cleaner it makes reviewing harder since I don't see what you have changed and always have to review the full change set. I've come to settle on individual commits and leave it to the maintainer to squash the commits if they want.

@magiconair magiconair added this to the v0.5.1 milestone Aug 22, 2023
@magiconair magiconair merged commit c792486 into gopcua:main Aug 22, 2023
1 of 5 checks passed
@sruehl
Copy link
Contributor Author

sruehl commented Aug 22, 2023

Usually I don't force push either but I read somewhere that it was requested to squash commits before merge so I started doing that from the start. But yes I agree: that makes following changes hard

@sruehl sruehl deleted the refactor/error_handling branch August 22, 2023 11:08
@magiconair
Copy link
Member

On this project? I'll have a look or can you point me to it...

@sruehl
Copy link
Contributor Author

sruehl commented Aug 22, 2023

Maybe my mind tricked me... I'll stick to normal commits for future PRs (or look if I can find that comment) 👍🏼
Btw just in case you didn't notice the little compare button on the right shows the diffs on force pushes too which is quite helpful
image

@magiconair
Copy link
Member

You'll learn something new every day :)

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.

Return error on NewClient
2 participants