From 5e65553d2770524db04342a36613aec4bbc4ed9b Mon Sep 17 00:00:00 2001 From: Jes Cok Date: Mon, 17 Jul 2023 13:14:15 +0800 Subject: [PATCH] pkg/expect: avoid hardcoding when checking 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 --- pkg/expect/expect.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/expect/expect.go b/pkg/expect/expect.go index 627ac576a39..b7e2978af5c 100644 --- a/pkg/expect/expect.go +++ b/pkg/expect/expect.go @@ -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 != nil && errors.Is(err, os.ErrProcessDone) { return nil } return err