Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format ConcurrencyException message #568

Merged
merged 7 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/YesSql.Abstractions/ConcurrencyException.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Reflection.Metadata;

namespace YesSql
{
public class ConcurrencyException : Exception
{
public ConcurrencyException() : base("The document could not be updated as it has been changed by another process.")
public Document Document { get; }

public ConcurrencyException(Document document) : base($"The document with Id '{document.Id}' and type '{document.Type}' could not be updated as it has been changed by another process.")
{
Document = document;
}
Copy link
Contributor Author

@hyzx86 hyzx86 Jun 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've formatted the error message and thrown it directly so that it doesn't need to be handled by an external application

}
}
2 changes: 1 addition & 1 deletion src/YesSql.Core/Commands/UpdateDocumentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public override async Task ExecuteAsync(DbConnection connection, DbTransaction t

if (_checkVersion > -1 && updatedCount != 1)
{
throw new ConcurrencyException();
throw new ConcurrencyException(Document);
}

return;
Expand Down
Loading