Closed MichaelDepner closed 6 months ago
I just created a test that creates a migration that fails, then called runner.Run():
[Fact]
public void Failed_migrations_throw()
{
var options = GetMigrationOptions();
options.Profiles.Add("migration that throws exception");
using var store = GetDocumentStore();
var runner = new MigrationRunner(store, options, new ConsoleLogger());
Assert.Throws<System.Exception>(() => runner.Run());
}
...
[Migration(6, "migration that throws exception")]
public class MigrationThrowsException : Migration
{
public override void Up()
{
throw new System.Exception("This is failing migration");
}
}
It throws the exception as expected. Is your call to runner.Run() inside a try/catch block?
I've committed the code for this test here.
Thanks for checking it out. I have done some digging, and it turns out I was misunderstanding how dotnet run
exit codes work. It returns 0
if it successfully builds and executes your application, and doesn't care what happens inside. Unless you manually pass the exit code along.
So in my case, this was the fix, and it had nothing to do with you:
await runner.InvokeAsync(args);
to
return await runner.InvokeAsync(args);
Thanks for looking into it anyway, I appreciate the help 🙏
I have noticed that my CI job that runs migrations always reports back that the job succeeded, even if a migration fails.
I tried running a faulty migration locally, and can see that it returns exit code 0 on failure, meaning the terminal sees the command as executed successfully. I assume there must be a
try/catch
out there that prints the exception info and then stops throwing it up the chain.Is this something you can help me figure out?
Example - a faulty migration throws an exception:![image](https://github.com/migrating-ravens/RavenMigrations/assets/657289/174a9b77-95aa-4423-816a-aa083a16492c)
And the end of the stack trace, showing that the program ended with exit code 0 - success:![image](https://github.com/migrating-ravens/RavenMigrations/assets/657289/586b695a-3eb9-4521-8159-0b23627c22e0)
Thanks in advance for the help / debugging