From 4e3d950885c201ac7e3c3e1fb7d105a8ef207291 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Tue, 14 Dec 2021 16:01:06 +0100 Subject: [PATCH] Fix InconsistentStateException, Closes #813 --- .../MongoDb/MongoExtensions.cs | 4 +-- .../Orleans/LoggingFilter.cs | 2 +- .../States/InconsistentStateException.cs | 26 +++++++++---------- .../States/InconsistentStateExceptionTests.cs | 4 +-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs index f4a645019..26cd1ad27 100644 --- a/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs +++ b/backend/src/Squidex.Infrastructure.MongoDb/MongoDb/MongoExtensions.cs @@ -132,11 +132,11 @@ namespace Squidex.Infrastructure.MongoDb { var field = Field.Of(x => nameof(x.Version)); - throw new InconsistentStateException(existingVersion[field].AsInt64, oldVersion, ex); + throw new InconsistentStateException(existingVersion[field].AsInt64, oldVersion); } else { - throw new InconsistentStateException(EtagVersion.Any, oldVersion, ex); + throw new InconsistentStateException(EtagVersion.Any, oldVersion); } } } diff --git a/backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs b/backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs index 23d9258c0..6c9152027 100644 --- a/backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs +++ b/backend/src/Squidex.Infrastructure/Orleans/LoggingFilter.cs @@ -6,6 +6,7 @@ // ========================================================================== using Orleans; +using Squidex.Infrastructure.States; using Squidex.Log; namespace Squidex.Infrastructure.Orleans @@ -37,7 +38,6 @@ namespace Squidex.Infrastructure.Orleans catch (Exception ex) { Log(context, ex); - throw; } } diff --git a/backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs b/backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs index 8d907f4db..4854e585d 100644 --- a/backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs +++ b/backend/src/Squidex.Infrastructure/States/InconsistentStateException.cs @@ -12,37 +12,35 @@ namespace Squidex.Infrastructure.States [Serializable] 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) - : base(FormatMessage(currentVersion, expectedVersion), inner) + public InconsistentStateException(long current, long expected, Exception? inner = null) + : base(FormatMessage(current, expected), inner) { - CurrentVersion = currentVersion; - - ExpectedVersion = expectedVersion; + VersionCurrent = current; + VersionExpected = expected; } protected InconsistentStateException(SerializationInfo info, StreamingContext context) : base(info, context) { - CurrentVersion = info.GetInt64(nameof(CurrentVersion)); - - ExpectedVersion = info.GetInt64(nameof(ExpectedVersion)); + VersionCurrent = info.GetInt64(nameof(VersionCurrent)); + VersionExpected = info.GetInt64(nameof(VersionExpected)); } public override void GetObjectData(SerializationInfo info, StreamingContext context) { - info.AddValue(nameof(CurrentVersion), CurrentVersion); - info.AddValue(nameof(ExpectedVersion), ExpectedVersion); + info.AddValue(nameof(VersionCurrent), VersionCurrent); + info.AddValue(nameof(VersionExpected), VersionExpected); 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}."; } } } diff --git a/backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs b/backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs index 679090467..a46dddd46 100644 --- a/backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs +++ b/backend/tests/Squidex.Infrastructure.Tests/States/InconsistentStateExceptionTests.cs @@ -22,8 +22,8 @@ namespace Squidex.Infrastructure.States Assert.Equal("Inner", result.InnerException?.Message); - Assert.Equal(result.ExpectedVersion, source.ExpectedVersion); - Assert.Equal(result.CurrentVersion, source.CurrentVersion); + Assert.Equal(result.VersionExpected, source.VersionExpected); + Assert.Equal(result.VersionCurrent, source.VersionCurrent); Assert.Equal(result.Message, source.Message); }