Skip to content

Fix #2054: Throw an exception if null is passed to Bulk() and fix NRE… #2055

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

Merged
merged 1 commit into from
Apr 22, 2016
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
8 changes: 4 additions & 4 deletions src/Nest/CommonAbstractions/Response/ResponseBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ public string DebugInformation
get
{
var sb = new StringBuilder();
sb.Append($"{(!IsValid ? "Inv" : "V")}alid NEST response built from a ");
sb.AppendLine(ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this");
sb.Append($"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a ");
sb.AppendLine(this.ApiCall?.ToString().ToCamelCase() ?? "null ApiCall which is highly exceptional, please open a bug if you see this");
if (!this.IsValid) this.DebugIsValid(sb);
ResponseStatics.DebugInformationBuilder(ApiCall, sb);
if (this.ApiCall != null) ResponseStatics.DebugInformationBuilder(ApiCall, sb);
return sb.ToString();
}
}
protected virtual void DebugIsValid(StringBuilder sb) { }

public override string ToString() => $"{(!IsValid ? "Inv" : "V")}alid NEST response built from a {this.ApiCall?.ToString().ToCamelCase()}";
public override string ToString() => $"{(!this.IsValid ? "Inv" : "V")}alid NEST response built from a {this.ApiCall?.ToString().ToCamelCase()}";

}
}
1 change: 1 addition & 0 deletions src/Nest/Document/Multiple/Bulk/BulkResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class BulkResponse : ResponseBase, IBulkResponse
public override bool IsValid => base.IsValid && !this.Errors && !this.ItemsWithErrors.HasAny();
protected override void DebugIsValid(StringBuilder sb)
{
if (this.Items == null) return;
sb.AppendLine($"# Invalid Bulk items:");
foreach(var i in Items.Select((item, i) => new { item, i}).Where(i=>!i.item.IsValid))
sb.AppendLine($" operation[{i.i}]: {i.item}");
Expand Down
26 changes: 18 additions & 8 deletions src/Nest/Document/Multiple/Bulk/ElasticClient-Bulk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Nest
public partial interface IElasticClient
{
/// <summary>
/// The bulk API makes it possible to perform many index/delete operations in a single API call.
/// The bulk API makes it possible to perform many index/delete operations in a single API call.
/// This can greatly increase the indexing speed.
/// <para> </para>http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/docs-bulk.html
/// </summary>
Expand All @@ -28,23 +28,33 @@ public partial interface IElasticClient
public partial class ElasticClient
{
/// <inheritdoc/>
public IBulkResponse Bulk(IBulkRequest request) =>
public IBulkResponse Bulk(IBulkRequest request) =>
this.Dispatcher.Dispatch<IBulkRequest, BulkRequestParameters, BulkResponse>(
request, this.LowLevelDispatch.BulkDispatch<BulkResponse>
);

/// <inheritdoc/>
public IBulkResponse Bulk(Func<BulkDescriptor, IBulkRequest> selector = null) =>
this.Bulk(selector.InvokeOrDefault(new BulkDescriptor()));
public IBulkResponse Bulk(Func<BulkDescriptor, IBulkRequest> selector = null)
{
// selector should not be nullable, but we can't change it for backwards compatibility reasons
if (selector == null)
throw new ArgumentNullException(nameof(selector));
return this.Bulk(selector.InvokeOrDefault(new BulkDescriptor()));
}

/// <inheritdoc/>
public Task<IBulkResponse> BulkAsync(IBulkRequest request) =>
public Task<IBulkResponse> BulkAsync(IBulkRequest request) =>
this.Dispatcher.DispatchAsync<IBulkRequest, BulkRequestParameters, BulkResponse, IBulkResponse>(
request, this.LowLevelDispatch.BulkDispatchAsync<BulkResponse>
);

/// <inheritdoc/>
public Task<IBulkResponse> BulkAsync(Func<BulkDescriptor, IBulkRequest> selector = null) =>
this.BulkAsync(selector.InvokeOrDefault(new BulkDescriptor()));
public Task<IBulkResponse> BulkAsync(Func<BulkDescriptor, IBulkRequest> selector = null)
{
// selector should not be nullable, but we can't change it for backwards compatibility reasons
if (selector == null)
throw new ArgumentNullException(nameof(selector));
return this.BulkAsync(selector.InvokeOrDefault(new BulkDescriptor()));
}
}
}
}