Skip to content

Commit

Permalink
Add trace log back and remove redundant catch for non rpc exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
w1am committed Feb 13, 2024
1 parent 9be6e8a commit ec5b31c
Showing 1 changed file with 20 additions and 30 deletions.
50 changes: 20 additions & 30 deletions src/EventStore.Client.Streams/EventStoreClient.Append.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,38 +105,28 @@ CancellationToken cancellationToken
);

IWriteResult writeResult;
try {
await call.RequestStream.WriteAsync(header).ConfigureAwait(false);

foreach (var e in eventData) {
await call.RequestStream.WriteAsync(
new AppendReq {
ProposedMessage = new AppendReq.Types.ProposedMessage {
Id = e.EventId.ToDto(),
Data = ByteString.CopyFrom(e.Data.Span),
CustomMetadata = ByteString.CopyFrom(e.Metadata.Span),
Metadata = {
{ Constants.Metadata.Type, e.Type },
{ Constants.Metadata.ContentType, e.ContentType }
}
},
}
).ConfigureAwait(false);
}

await call.RequestStream.CompleteAsync().ConfigureAwait(false);
} catch (Exception ex) {
if (ex is not RpcException) {
_log.LogError(
ex,
"Append to stream failed with unexpected error - {streamName}@{expectedRevision}",
header.Options.StreamIdentifier,
header.Options.Revision
);
throw;
}
await call.RequestStream.WriteAsync(header).ConfigureAwait(false);

foreach (var e in eventData) {
_log.LogTrace("Appending event to stream - {streamName}@{eventId} {eventType}.",
header.Options.StreamIdentifier, e.EventId, e.Type);
await call.RequestStream.WriteAsync(
new AppendReq {
ProposedMessage = new AppendReq.Types.ProposedMessage {
Id = e.EventId.ToDto(),
Data = ByteString.CopyFrom(e.Data.Span),
CustomMetadata = ByteString.CopyFrom(e.Metadata.Span),
Metadata = {
{ Constants.Metadata.Type, e.Type },
{ Constants.Metadata.ContentType, e.ContentType }
}
},
}
).ConfigureAwait(false);
}

await call.RequestStream.CompleteAsync().ConfigureAwait(false);

var response = await call.ResponseAsync.ConfigureAwait(false);

if (response.Success != null) {
Expand Down

0 comments on commit ec5b31c

Please sign in to comment.