Skip to content

Commit 14e8033

Browse files
gmarzMpdreamz
authored andcommitted
Remove ResolveException and let exceptions either bubble out or (#2426)
be wrapped within UnexpectedElasticsearchClientException if they occur late in the transport pipeline. Closes #1958
1 parent 8dd084d commit 14e8033

File tree

7 files changed

+16
-36
lines changed

7 files changed

+16
-36
lines changed

src/Elasticsearch.Net/Elasticsearch.Net.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@
8282
<Compile Include="ElasticLowLevelClient.cs" />
8383
<Compile Include="ElasticLowLevelClient.Generated.cs" />
8484
<Compile Include="Exceptions\ElasticsearchClientException.cs" />
85-
<Compile Include="Exceptions\ResolveException.cs" />
8685
<Compile Include="Exceptions\UnexpectedElasticsearchClientException.cs" />
8786
<Compile Include="Extensions\EnumExtensions.cs" />
8887
<Compile Include="Extensions\Extensions.cs" />

src/Elasticsearch.Net/Exceptions/ResolveException.cs

Lines changed: 0 additions & 13 deletions
This file was deleted.

src/Elasticsearch.Net/Transport/Transport.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,10 +84,6 @@ public ElasticsearchResponse<TReturn> Request<TReturn>(HttpMethod method, string
8484
pipeline.MarkDead(node);
8585
seenExceptions.Add(pipelineException);
8686
}
87-
catch (ResolveException)
88-
{
89-
throw;
90-
}
9187
catch (Exception killerException)
9288
{
9389
throw new UnexpectedElasticsearchClientException(killerException, seenExceptions)
@@ -149,10 +145,6 @@ public async Task<ElasticsearchResponse<TReturn>> RequestAsync<TReturn>(HttpMeth
149145
pipeline.MarkDead(node);
150146
seenExceptions.Add(pipelineException);
151147
}
152-
catch (ResolveException)
153-
{
154-
throw;
155-
}
156148
catch (Exception killerException)
157149
{
158150
throw new UnexpectedElasticsearchClientException(killerException, seenExceptions)

src/Nest/CommonAbstractions/Infer/Field/FieldResolver.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private string Resolve(Expression expression, MemberInfo member, bool toLastToke
8080
: null;
8181

8282
if (name == null)
83-
throw new ResolveException("Name resolved to null for the given Expression or MemberInfo.");
83+
throw new ArgumentException("Name resolved to null for the given Expression or MemberInfo.");
8484

8585
return name;
8686
}

src/Nest/CommonAbstractions/Infer/IndexName/IndexNameResolver.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public string Resolve(Type type)
3939
private static void ValidateIndexName(string indexName)
4040
{
4141
if (string.IsNullOrWhiteSpace(indexName))
42-
throw new ResolveException(
42+
throw new ArgumentException(
4343
"Index name is null for the given type and no default index is set. "
4444
+ "Map an index name using ConnectionSettings.MapDefaultTypeIndices() "
4545
+ "or set a default index using ConnectionSettings.DefaultIndex()."
4646
);
4747

4848
if (indexName.HasAny(char.IsUpper))
49-
throw new ResolveException($"Index names cannot contain uppercase characters: {indexName}.");
49+
throw new ArgumentException($"Index names cannot contain uppercase characters: {indexName}.");
5050
}
5151
}
5252
}

src/Tests/ClientConcepts/HighLevel/Inference/IndexNameInference.doc.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ [U] public void ExplicitIndexOnRequestTakesPrecedence()
100100
}
101101

102102
//hide
103-
[U] public void UppercaseCharacterThrowsResolveException()
103+
[U] public void UppercaseCharacterThrowsArgumentException()
104104
{
105105
var settings = new ConnectionSettings()
106106
.DefaultIndex("Default")
@@ -110,28 +110,30 @@ [U] public void UppercaseCharacterThrowsResolveException()
110110

111111
var resolver = new IndexNameResolver(settings);
112112

113-
var e = Assert.Throws<ResolveException>(() => resolver.Resolve<Project>());
113+
var e = Assert.Throws<ArgumentException>(() => resolver.Resolve<Project>());
114114
e.Message.Should().Be($"Index names cannot contain uppercase characters: myProjects.");
115-
e = Assert.Throws<ResolveException>(() => resolver.Resolve<Tag>());
115+
116+
e = Assert.Throws<ArgumentException>(() => resolver.Resolve<Tag>());
116117
e.Message.Should().Be($"Index names cannot contain uppercase characters: Default.");
117-
e = Assert.Throws<ResolveException>(() => resolver.Resolve("Foo"));
118+
119+
e = Assert.Throws<ArgumentException>(() => resolver.Resolve("Foo"));
118120
e.Message.Should().Be($"Index names cannot contain uppercase characters: Foo.");
119121
}
120122

121123
//hide
122-
[U] public void NoIndexThrowsResolveException()
124+
[U] public void NoIndexThrowsArgumentException()
123125
{
124126
var settings = new ConnectionSettings();
125127
var resolver = new IndexNameResolver(settings);
126-
var e = Assert.Throws<ResolveException>(() => resolver.Resolve<Project>());
128+
var e = Assert.Throws<ArgumentException>(() => resolver.Resolve<Project>());
127129
e.Message.Should().Contain("Index name is null");
128130
}
129131

130132
//hide
131-
[U] public void ResolveExceptionBubblesOut()
133+
[U] public void ArgumentExceptionBubblesOut()
132134
{
133135
var client = TestClient.GetClient(s => new ConnectionSettings());
134-
var e = Assert.Throws<ResolveException>(() => client.Search<Project>());
136+
var e = Assert.Throws<ArgumentException>(() => client.Search<Project>());
135137
}
136138
}
137139
}

src/Tests/ClientConcepts/LowLevel/Connecting.doc.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,12 +131,12 @@ public void AvailableOptions()
131131
* root causing exception.
132132
*
133133
* `UnexpectedElasticsearchClientException`:: These are unknown exceptions, for instance a response from Elasticsearch not
134-
* properly deserialized. These are usually bugs and {github}/issues[should be reported]. This exception also inherits from `ElasticsearchClientException`
134+
* properly deserialized. These are sometimes bugs and {github}/issues[should be reported]. This exception also inherits from `ElasticsearchClientException`
135135
* so an additional catch block isn't necessary, but can be helpful in distinguishing between the two.
136136
*
137137
* Development time exceptions:: These are CLR exceptions like `ArgumentException`, `ArgumentOutOfRangeException`, etc.
138-
* that are thrown when an API in the client is misused.
139-
* These should not be handled as you want to know about them during development.
138+
* that are thrown when an API in the client is misused. The `.ThrowExceptions()` setting has no bearing on these as
139+
* they will always be thrown, and also should not be handled by a consumer.
140140
*
141141
*/
142142
}

0 commit comments

Comments
 (0)