Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Fixed two issues regarding BufferCleanPayload (#295)
Browse files Browse the repository at this point in the history
I fixed a logical test issue that made the code to not go through the
cleanup path when errors happened and a issue with the error message
where a ToString was called on a dictionary resulting in the type name
instead of the actual error message. I refrained from adding the
detailed errors provided by elastic, because they can be many and
ridiculously detailed
  • Loading branch information
daniel-oster authored and mivano committed Nov 13, 2019
1 parent 5fe45bd commit e16bb2e
Showing 1 changed file with 6 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task<SentPayloadResult> SendPayloadAsync(List<string> payload, bool
{
var cleanPayload = new List<string>();
var invalidPayload = GetInvalidPayloadAsync(response, payload, out cleanPayload);
if ((cleanPayload?.Any() == false) && first)
if ((cleanPayload?.Any() ?? false) && first)
{
await SendPayloadAsync(cleanPayload, false);
}
Expand Down Expand Up @@ -96,20 +96,22 @@ private InvalidResult GetInvalidPayloadAsync(DynamicResponse baseResult, List<st
hasErrors = true;
var id = itemIndex?["_id"];
var error = itemIndex?["error"];
var errorString = $"type: {error?["type"] ?? "Unknown"}, reason: {error?["reason"] ?? "Unknown"}";

if (int.TryParse(id.Split('_')[0], out int index))
{
SelfLog.WriteLine("Received failed ElasticSearch shipping result {0}: {1}. Failed payload : {2}.", status, error?.ToString(), payload.ElementAt(index * 2 + 1));
SelfLog.WriteLine("Received failed ElasticSearch shipping result {0}: {1}. Failed payload : {2}.", status, errorString, payload.ElementAt(index * 2 + 1));
badPayload.Add(payload.ElementAt(index * 2));
badPayload.Add(payload.ElementAt(index * 2 + 1));
if (_cleanPayload != null)
{
cleanPayload.Add(payload.ElementAt(index * 2));
cleanPayload.Add(_cleanPayload(payload.ElementAt(index * 2 + 1), status, error?.ToString()));
cleanPayload.Add(_cleanPayload(payload.ElementAt(index * 2 + 1), status, errorString));
}
}
else
{
SelfLog.WriteLine($"Received failed ElasticSearch shipping result {status}: {error?.ToString()}.");
SelfLog.WriteLine($"Received failed ElasticSearch shipping result {status}: {errorString}.");
}
}

Expand Down

0 comments on commit e16bb2e

Please sign in to comment.