Browse Source

Fix InconsistentStateException, Closes #813

pull/815/head
Sebastian 4 years ago
parent
commit
4e3d950885
  1. 4
      backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs
  2. 2
      backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs
  3. 26
      backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs
  4. 4
      backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs

4
backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs

@ -132,11 +132,11 @@ namespace Squidex.Infrastructure.MongoDb
{ {
var field = Field.Of<T>(x => nameof(x.Version)); var field = Field.Of<T>(x => nameof(x.Version));
throw new InconsistentStateException(existingVersion[field].AsInt64, oldVersion, ex); throw new InconsistentStateException(existingVersion[field].AsInt64, oldVersion);
} }
else else
{ {
throw new InconsistentStateException(EtagVersion.Any, oldVersion, ex); throw new InconsistentStateException(EtagVersion.Any, oldVersion);
} }
} }
} }

2
backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs

@ -6,6 +6,7 @@
// ========================================================================== // ==========================================================================
using Orleans; using Orleans;
using Squidex.Infrastructure.States;
using Squidex.Log; using Squidex.Log;
namespace Squidex.Infrastructure.Orleans namespace Squidex.Infrastructure.Orleans
@ -37,7 +38,6 @@ namespace Squidex.Infrastructure.Orleans
catch (Exception ex) catch (Exception ex)
{ {
Log(context, ex); Log(context, ex);
throw; throw;
} }
} }

26
backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs

@ -12,37 +12,35 @@ namespace Squidex.Infrastructure.States
[Serializable] [Serializable]
public class InconsistentStateException : Exception public class InconsistentStateException : Exception
{ {
public long CurrentVersion { get; } public long VersionCurrent { get; }
public long ExpectedVersion { get; } public long VersionExpected { get; }
public InconsistentStateException(long currentVersion, long expectedVersion, Exception? inner = null) public InconsistentStateException(long current, long expected, Exception? inner = null)
: base(FormatMessage(currentVersion, expectedVersion), inner) : base(FormatMessage(current, expected), inner)
{ {
CurrentVersion = currentVersion; VersionCurrent = current;
VersionExpected = expected;
ExpectedVersion = expectedVersion;
} }
protected InconsistentStateException(SerializationInfo info, StreamingContext context) protected InconsistentStateException(SerializationInfo info, StreamingContext context)
: base(info, context) : base(info, context)
{ {
CurrentVersion = info.GetInt64(nameof(CurrentVersion)); VersionCurrent = info.GetInt64(nameof(VersionCurrent));
VersionExpected = info.GetInt64(nameof(VersionExpected));
ExpectedVersion = info.GetInt64(nameof(ExpectedVersion));
} }
public override void GetObjectData(SerializationInfo info, StreamingContext context) public override void GetObjectData(SerializationInfo info, StreamingContext context)
{ {
info.AddValue(nameof(CurrentVersion), CurrentVersion); info.AddValue(nameof(VersionCurrent), VersionCurrent);
info.AddValue(nameof(ExpectedVersion), ExpectedVersion); info.AddValue(nameof(VersionExpected), VersionExpected);
base.GetObjectData(info, context); base.GetObjectData(info, context);
} }
private static string FormatMessage(long currentVersion, long expectedVersion) private static string FormatMessage(long current, long expected)
{ {
return $"Requested version {expectedVersion}, but found {currentVersion}."; return $"Requested version {expected}, but found {current}.";
} }
} }
} }

4
backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs

@ -22,8 +22,8 @@ namespace Squidex.Infrastructure.States
Assert.Equal("Inner", result.InnerException?.Message); Assert.Equal("Inner", result.InnerException?.Message);
Assert.Equal(result.ExpectedVersion, source.ExpectedVersion); Assert.Equal(result.VersionExpected, source.VersionExpected);
Assert.Equal(result.CurrentVersion, source.CurrentVersion); Assert.Equal(result.VersionCurrent, source.VersionCurrent);
Assert.Equal(result.Message, source.Message); Assert.Equal(result.Message, source.Message);
} }

Loading…
Cancel
Save