From de9e7d9a41c73b7144e10e3a1a73af683e3114a5 Mon Sep 17 00:00:00 2001 From: NiseVoid Date: Mon, 28 Oct 2019 13:01:29 +0100 Subject: [PATCH] Add filename to error message --- migrate.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/migrate.go b/migrate.go index dcc4b29..96bd542 100644 --- a/migrate.go +++ b/migrate.go @@ -67,19 +67,22 @@ func Migrate(db *sql.DB, version int, o Options, asset AssetFunc) error { } for i := v + 1; i <= version; i++ { - script, err := asset(fmt.Sprintf(o.AssetPrefix+fileFormat, i)) + fileName := fmt.Sprintf(o.AssetPrefix+fileFormat, i) + errorf := func(e error) error { return fmt.Errorf(`migration "%s" failed: %w`, fileName, e) } + + script, err := asset(fileName) if err != nil { - return ErrUpdatesMissing + return errorf(ErrUpdatesMissing) } _, err = tx.Exec(string(script)) if err != nil { - return err + return errorf(err) } _, err = tx.Exec(`INSERT INTO ` + o.TableName + ` VALUES (` + strconv.Itoa(i) + `)`) if err != nil { - return err + return errorf(err) } }