Skip to content

Commit ced3b84

Browse files
committed
Wrap migration runtime errors to call out which migration caused them.
1 parent be19ad3 commit ced3b84

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/Rezoom.SQL.Mapping/Migrations.fs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ type MigrationConfig =
146146
LogMigrationRan = fun _ -> ()
147147
}
148148

149+
type MigrationRuntimeException(migrationName : string, inner : Exception) =
150+
inherit Exception("Error running migration " + migrationName + ": " + inner.Message, inner)
151+
149152
module MigrationUtilities =
150153
let private quotationizeMigration (migration : string Migration) =
151154
<@@ { MajorVersion = %%Expr.Value(migration.MajorVersion)
@@ -187,7 +190,10 @@ module MigrationUtilities =
187190
migration.MajorVersion migration.Name
188191
currentMajorVersion
189192
else
190-
backend.RunMigration(migration)
193+
try
194+
backend.RunMigration(migration)
195+
with
196+
| exn -> raise (MigrationRuntimeException(migration.MigrationName, exn))
191197
config.LogMigrationRan migration
192198
ignore <| already.Add(pair) // actually we don't need this but ok
193199

0 commit comments

Comments
 (0)