Browse Source

* Proper exception for migration problem.

pull/403/head
Sebastian Stehle 6 years ago
parent
commit
52946d9a61
  1. 46
      src/Squidex.Infrastructure/Migrations/MigrationFailedException.cs
  2. 2
      src/Squidex.Infrastructure/Migrations/Migrator.cs
  3. 4
      tests/Squidex.Infrastructure.Tests/Migrations/MigratorTests.cs

46
src/Squidex.Infrastructure/Migrations/MigrationFailedException.cs

@ -0,0 +1,46 @@
// ==========================================================================
// Squidex Headless CMS
// ==========================================================================
// Copyright (c) Squidex UG (haftungsbeschraenkt)
// All rights reserved. Licensed under the MIT license.
// ==========================================================================
using System;
using System.Runtime.Serialization;
namespace Squidex.Infrastructure.Migrations
{
[Serializable]
public class MigrationFailedException : Exception
{
public string Name { get; }
public MigrationFailedException(string name)
: base(FormatException(name))
{
Name = name;
}
public MigrationFailedException(string name, Exception inner)
: base(FormatException(name), inner)
{
Name = name;
}
protected MigrationFailedException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
Name = info.GetString(nameof(Name));
}
public override void GetObjectData(SerializationInfo info, StreamingContext context)
{
info.AddValue(nameof(Name), Name);
}
private static string FormatException(string name)
{
return $"Failed to run migration '{name}'";
}
}
}

2
src/Squidex.Infrastructure/Migrations/Migrator.cs

@ -84,7 +84,7 @@ namespace Squidex.Infrastructure.Migrations
.WriteProperty("status", "Failed")
.WriteProperty("migrator", name));
throw;
throw new MigrationFailedException(name, ex);
}
}

4
tests/Squidex.Infrastructure.Tests/Migrations/MigratorTests.cs

@ -152,9 +152,9 @@ namespace Squidex.Infrastructure.Migrations
var sut = new Migrator(status, path, log);
await Assert.ThrowsAsync<InvalidOperationException>(() => sut.MigrateAsync());
await Assert.ThrowsAsync<MigrationFailedException>(() => sut.MigrateAsync());
A.CallTo(() => log.Log<None>(SemanticLogLevel.Fatal, default, A<Action<None, IObjectWriter>>.Ignored))
A.CallTo(() => log.Log(SemanticLogLevel.Fatal, default, A<Action<None, IObjectWriter>>.Ignored))
.MustHaveHappened();
A.CallTo(() => migrator_1_2.UpdateAsync())

Loading…
Cancel
Save