From 77950fe3011e3939e8e3457a5855d44bfacce4d1 Mon Sep 17 00:00:00 2001 From: TangoEnSkai <21152231+TangoEnSkai@users.noreply.github.com> Date: Sat, 22 Aug 2026 12:05:30 +0900 Subject: [PATCH] fix: return underlying error in EnsureMigrationTable instead of swallowing it EnsureMigrationTable treated any read error as "table does not exist" and unconditionally attempted to create the migration table. This masked real failures such as permission errors or deadlines, since the CREATE TABLE call would then fail with a confusing or misleading error instead of the original one. Now only a NotFound error is treated as "table does not exist"; any other error is returned wrapped in the existing Error type. Fixes #114 --- pkg/spanner/client.go | 7 +++++++ pkg/spanner/errors.go | 1 + 2 files changed, 8 insertions(+) diff --git a/pkg/spanner/client.go b/pkg/spanner/client.go index 68e9898..9997246 100644 --- a/pkg/spanner/client.go +++ b/pkg/spanner/client.go @@ -33,6 +33,7 @@ import ( "github.com/hashicorp/go-multierror" "google.golang.org/api/iterator" "google.golang.org/api/option" + "google.golang.org/grpc/codes" ) const ( @@ -491,6 +492,12 @@ func (c *Client) EnsureMigrationTable(ctx context.Context, tableName string) err if err == nil { return nil } + if spanner.ErrCode(err) != codes.NotFound { + return &Error{ + Code: ErrorCodeEnsureMigrationTable, + err: err, + } + } stmt := fmt.Sprintf("CREATE TABLE `%s` ("+` Version INT64 NOT NULL, diff --git a/pkg/spanner/errors.go b/pkg/spanner/errors.go index 3e04121..222e8b7 100644 --- a/pkg/spanner/errors.go +++ b/pkg/spanner/errors.go @@ -41,6 +41,7 @@ const ( ErrorCodeWaitOperation ErrorCodeCreateInstance ErrorCodeDeleteInstance + ErrorCodeEnsureMigrationTable ) type Error struct {