From 204493173e26fcb07362804142e3e722a657216e Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Fri, 11 Sep 2020 11:56:18 +0200 Subject: remote run: fix error checks As error types are not preserved on the client side (due to marshaling), we cannot use `errors.Cause(...)` and friends but, unfortunately, have to fall back to looking for substring the error messages. Change the error checks in remote run to do substring matches and fix issue #7340. Fixes: #7340 Signed-off-by: Valentin Rothberg --- pkg/errorhandling/errorhandling.go | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'pkg/errorhandling/errorhandling.go') diff --git a/pkg/errorhandling/errorhandling.go b/pkg/errorhandling/errorhandling.go index 3117b0ca4..ca6b60bc5 100644 --- a/pkg/errorhandling/errorhandling.go +++ b/pkg/errorhandling/errorhandling.go @@ -57,3 +57,11 @@ func CloseQuiet(f *os.File) { logrus.Errorf("unable to close file %s: %q", f.Name(), err) } } + +// Contains checks if err's message contains sub's message. Contains should be +// used iff either err or sub has lost type information (e.g., due to +// marshaling). For typed errors, please use `errors.Contains(...)` or `Is()` +// in recent version of Go. +func Contains(err error, sub error) bool { + return strings.Contains(err.Error(), sub.Error()) +} -- cgit v1.2.3-54-g00ecf