From cd53b98dc8f3d283a27a17e18cd336d75fff4dea Mon Sep 17 00:00:00 2001 From: Rotem Tamir Date: Thu, 28 Dec 2023 13:29:24 +0200 Subject: [PATCH] controllers: adapt to error message change for sql exec errs --- controllers/atlasschema_controller_test.go | 10 ++++++++++ controllers/common.go | 3 ++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/controllers/atlasschema_controller_test.go b/controllers/atlasschema_controller_test.go index 092fe556..d98f8022 100644 --- a/controllers/atlasschema_controller_test.go +++ b/controllers/atlasschema_controller_test.go @@ -730,3 +730,13 @@ func events(r record.EventRecorder) []string { } } } + +// Versions after v0.17 of Atlas return a slightly more readable error message. This test +// ensures we support both formats. +func TestSQLErrRegression(t *testing.T) { + m := `executing statement "create table bar (id int)"` + e1 := fmt.Errorf(`sql/migrate: execute: %s`, m) + e2 := fmt.Errorf(`sql/migrate: %s`, m) + require.True(t, isSQLErr(e1)) + require.True(t, isSQLErr(e2)) +} diff --git a/controllers/common.go b/controllers/common.go index 15be386f..73670eaa 100644 --- a/controllers/common.go +++ b/controllers/common.go @@ -79,6 +79,7 @@ var ( }). ParseFS(tmpls, "templates/*.tmpl"), ) + sqlErrRegex = regexp.MustCompile(`sql/migrate: (execute: )?executing statement`) ) func getConfigMap(ctx context.Context, r client.Reader, ns string, ref *corev1.LocalObjectReference) (*corev1.ConfigMap, error) { @@ -116,7 +117,7 @@ func isSQLErr(err error) bool { if err == nil { return false } - return strings.Contains(err.Error(), "sql/migrate: execute: executing statement") + return sqlErrRegex.MatchString(err.Error()) } // isChecksumErr returns true if the error is a checksum error.