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

pkg/expect: avoid hardcoding when checking ErrProcessDone #16252

Merged
merged 1 commit into from
Jul 18, 2023
Merged

pkg/expect: avoid hardcoding when checking ErrProcessDone #16252

merged 1 commit into from
Jul 18, 2023

Conversation

callthingsoff
Copy link
Contributor

ExpectProcess's Stop method uses 'strings.Contains' to check the returned err, however, this can be avoided. os.ErrProcessDone's error message is the same as the hardcoded string. So I think this explicit error is what this method wants to compare.

@@ -286,7 +286,7 @@ func (ep *ExpectProcess) ExitError() error {
// Stop signals the process to terminate via SIGTERM
func (ep *ExpectProcess) Stop() error {
err := ep.Signal(syscall.SIGTERM)
if err != nil && strings.Contains(err.Error(), "os: process already finished") {
if err == os.ErrProcessDone {
Copy link
Member

Choose a reason for hiding this comment

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

Should we use if err != nil && errors.Is(err, os.ErrProcessDone) here? I think it is easy to read and it's better to check err compatible with Is instead of equal. WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be clear, I don't want to abuse 'errors.Is'. However It's harmless, I'll change it.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the update. For the errors.Is, since the function or interface might enhance the error message with fmt.Errorf, it's hard to track the change. It might happen that the err is not os.ErrProcessDone but the main cause it is. So, it's just my two cents.

Copy link
Contributor Author

@callthingsoff callthingsoff Jul 17, 2023

Choose a reason for hiding this comment

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

Thanks, I understand.
I also noticed this code go/src/cmd/go/internal/vcweb/hg.go at line 62.

if err != nil && !errors.Is(err, os.ErrProcessDone)

ExpectProcess's Stop method uses 'strings.Contains' to check
the returned err, however, this can be avoided. os.ErrProcessDone's
error message is the same as the hardcoded string. So I think
this explicit error is what this method wants to compare.

Signed-off-by: Jes Cok <xigua67damn@gmail.com>
Copy link
Member

@ahrtr ahrtr left a comment

Choose a reason for hiding this comment

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

LGTM

thx @gocurr

Copy link
Member

@fuweid fuweid left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@jmhbnz jmhbnz left a comment

Choose a reason for hiding this comment

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

LGTM

@ahrtr ahrtr merged commit 7aad281 into etcd-io:main Jul 18, 2023
27 checks passed
@callthingsoff callthingsoff deleted the avoid_hardcoding branch July 18, 2023 11:37
@jmhbnz jmhbnz mentioned this pull request Sep 25, 2023
9 tasks
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.

5 participants