Skip to content

Commit 6d80069

Browse files
committed
Throw ArgumentException on type mismatches.
1 parent 7ca45f8 commit 6d80069

File tree

3 files changed

+24
-24
lines changed

3 files changed

+24
-24
lines changed

sources/TileDB.CSharp/ThrowHelpers.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ public static void ThrowTypeNotSupported() =>
1717
// We don't have to specify the type in the type argument, it can be seen from the stacktrace.
1818
[DoesNotReturn]
1919
public static void ThrowTypeMismatch(DataType type) =>
20-
throw new InvalidOperationException($"Type is not compatible with data type {type}.");
20+
throw new ArgumentException($"Type is not compatible with data type {type}.");
2121

2222
[DoesNotReturn]
2323
public static void ThrowStringTypeMismatch(DataType type) =>
24-
throw new InvalidOperationException($"Cannot encode data type {type} into strings.");
24+
throw new ArgumentException($"Cannot encode data type {type} into strings.");
2525

2626
[DoesNotReturn]
2727
public static void ThrowTooBigSize(ulong size, [CallerArgumentExpression(nameof(size))] string? paramName = null) =>

tests/TileDB.CSharp.Test/FragmentInfoTest.cs

+16-16
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,11 @@ public void TestMinimumBoundedRectanglesString()
172172
Assert.AreEqual(("a", "bb"), info.GetMinimumBoundedRectangle<string>(0, 0, 0));
173173
Assert.AreEqual(("c", "ddd"), info.GetMinimumBoundedRectangle<string>(0, 1, "d"));
174174

175-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<int>(0, 0, 0));
176-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<long>(0, 0, 0));
175+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<int>(0, 0, 0));
176+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<long>(0, 0, 0));
177177
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(0, 0, 0));
178-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<int>(0, 1, "d"));
179-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<long>(0, 1, "d"));
178+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<int>(0, 1, "d"));
179+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<long>(0, 1, "d"));
180180
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(0, 1, "d"));
181181
}
182182

@@ -199,11 +199,11 @@ public void TestMinimumBoundedRectangles()
199199
Assert.AreEqual((1, 2), info.GetMinimumBoundedRectangle<long>(0, 0, 0));
200200
Assert.AreEqual((7, 8), info.GetMinimumBoundedRectangle<long>(1, 1, "d1"));
201201

202-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<int>(0, 0, 0));
203-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<string>(0, 0, 0));
202+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<int>(0, 0, 0));
203+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<string>(0, 0, 0));
204204
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(0, 0, 0));
205-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<int>(1, 1, "d1"));
206-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<string>(1, 1, "d1"));
205+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<int>(1, 1, "d1"));
206+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<string>(1, 1, "d1"));
207207
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(1, 1, "d1"));
208208
}
209209

@@ -226,11 +226,11 @@ public void TestMinimumBoundedRectanglesInt32()
226226
Assert.AreEqual((1, 2), info.GetMinimumBoundedRectangle<int>(0, 0, 0));
227227
Assert.AreEqual((7, 8), info.GetMinimumBoundedRectangle<int>(1, 1, "d1"));
228228

229-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<long>(0, 0, 0));
230-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<string>(0, 0, 0));
229+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<long>(0, 0, 0));
230+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<string>(0, 0, 0));
231231
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(0, 0, 0));
232-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<long>(1, 1, "d1"));
233-
Assert.ThrowsException<InvalidOperationException>(() => info.GetMinimumBoundedRectangle<string>(1, 1, "d1"));
232+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<long>(1, 1, "d1"));
233+
Assert.ThrowsException<ArgumentException>(() => info.GetMinimumBoundedRectangle<string>(1, 1, "d1"));
234234
Assert.ThrowsException<NotSupportedException>(() => info.GetMinimumBoundedRectangle<Guid>(1, 1, "d1"));
235235
}
236236

@@ -268,8 +268,8 @@ public void TestNonEmptyDomain()
268268
(int Start, int End, _) => (Start, End)
269269
};
270270
Assert.AreEqual(expectedNonEmptyDomain, actualNonEmptyDomain);
271-
Assert.ThrowsException<InvalidOperationException>(() => info.GetNonEmptyDomain<long>(i, dim));
272-
Assert.ThrowsException<InvalidOperationException>(() => info.GetNonEmptyDomain<string>(i, dim));
271+
Assert.ThrowsException<ArgumentException>(() => info.GetNonEmptyDomain<long>(i, dim));
272+
Assert.ThrowsException<ArgumentException>(() => info.GetNonEmptyDomain<string>(i, dim));
273273
Assert.ThrowsException<NotSupportedException>(() => info.GetNonEmptyDomain<Guid>(i, dim));
274274

275275
string name = d.Name();
@@ -279,8 +279,8 @@ public void TestNonEmptyDomain()
279279
(int Start, int End, _) => (Start, End)
280280
};
281281
Assert.AreEqual(expectedNonEmptyDomain, actualNonEmptyDomain);
282-
Assert.ThrowsException<InvalidOperationException>(() => info.GetNonEmptyDomain<long>(i, name));
283-
Assert.ThrowsException<InvalidOperationException>(() => info.GetNonEmptyDomain<string>(i, name));
282+
Assert.ThrowsException<ArgumentException>(() => info.GetNonEmptyDomain<long>(i, name));
283+
Assert.ThrowsException<ArgumentException>(() => info.GetNonEmptyDomain<string>(i, name));
284284
Assert.ThrowsException<NotSupportedException>(() => info.GetNonEmptyDomain<Guid>(i, name));
285285
}
286286
}

tests/TileDB.CSharp.Test/QueryTest.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ public void TestGlobalQuery(LayoutType layoutType, ArrayType arrayType)
5050
{
5151
using var subarray = new Subarray(array);
5252
subarray.AddRange("rows", 1, 4);
53-
Assert.ThrowsException<InvalidOperationException>(() => subarray.AddRange<long>("rows", 1, 4));
53+
Assert.ThrowsException<ArgumentException>(() => subarray.AddRange<long>("rows", 1, 4));
5454
Assert.AreEqual((1, 4), subarray.GetRange<int>("rows", 0));
55-
Assert.ThrowsException<InvalidOperationException>(() => subarray.GetRange<long>("rows", 0));
55+
Assert.ThrowsException<ArgumentException>(() => subarray.GetRange<long>("rows", 0));
5656
subarray.AddRange(1, 1, 2); // cols
57-
Assert.ThrowsException<InvalidOperationException>(() => subarray.AddRange<long>(1, 1, 2));
57+
Assert.ThrowsException<ArgumentException>(() => subarray.AddRange<long>(1, 1, 2));
5858
Assert.AreEqual((1, 2), subarray.GetRange<int>(1, 0));
59-
Assert.ThrowsException<InvalidOperationException>(() => subarray.GetRange<long>(1, 0));
59+
Assert.ThrowsException<ArgumentException>(() => subarray.GetRange<long>(1, 0));
6060
queryWrite.SetSubarray(subarray);
6161
queryWrite.SetDataReadOnlyBuffer<int>("a1", new[] { 1, 2, 3, 4, 5, 6, 7, 8 }.AsMemory());
6262
}
@@ -181,8 +181,8 @@ public void TestDenseQuery()
181181
using (var subarray = new Subarray(array))
182182
{
183183
subarray.SetSubarray<sbyte>(0, 1);
184-
Assert.ThrowsException<InvalidOperationException>(() => subarray.SetSubarray(0, 1));
185-
Assert.ThrowsException<InvalidOperationException>(() => subarray.SetSubarray(0));
184+
Assert.ThrowsException<ArgumentException>(() => subarray.SetSubarray(0, 1));
185+
Assert.ThrowsException<ArgumentException>(() => subarray.SetSubarray(0));
186186
query.SetSubarray(subarray);
187187
}
188188

0 commit comments

Comments
 (0)