Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 8611d01

Browse files
committed
rethrow exceptions in InsertAllAsync/UpdateAllAsync API's
1 parent b67cf15 commit 8611d01

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

src/ServiceStack.OrmLite/Async/OrmLiteWriteCommandExtensionsAsync.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ internal static Task<int> UpdateAllAsync<T>(this IDbCommand dbCmd, IEnumerable<T
9999
if (dbTrans != null)
100100
dbTrans.Dispose();
101101

102+
if (t.IsFaulted)
103+
throw t.Exception;
104+
102105
return count;
103106
});
104107
}
@@ -291,6 +294,9 @@ internal static Task InsertAllAsync<T>(this IDbCommand dbCmd, IEnumerable<T> obj
291294

292295
if (dbTrans != null)
293296
dbTrans.Dispose();
297+
298+
if (t.IsFaulted)
299+
throw t.Exception;
294300
});
295301
}
296302

tests/ServiceStack.OrmLiteV45.Tests/AsyncTests.cs

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
using System.Threading;
1+
using System;
2+
using System.Threading;
23
using System.Threading.Tasks;
34
using NUnit.Framework;
45
using ServiceStack.Common.Tests.Models;
6+
using ServiceStack.DataAnnotations;
57
using ServiceStack.Text;
68

79
using ServiceStack.OrmLite.Tests.Shared;
@@ -35,6 +37,70 @@ public async Task Can_Insert_and_SelectAsync()
3537
}
3638
}
3739

40+
[Test]
41+
public async Task Does_throw_async_errors()
42+
{
43+
using (var db = OpenDbConnection())
44+
{
45+
db.DropAndCreateTable<Poco>();
46+
47+
try
48+
{
49+
var results = await db.SelectAsync<Poco>(q => q.Where("NotExists = 1"));
50+
Assert.Fail("Should throw");
51+
}
52+
catch (Exception ex)
53+
{
54+
Assert.That(ex.Message, Is.StringContaining("Id").Or.StringContaining("NotExists"));
55+
}
56+
57+
try
58+
{
59+
await db.InsertAsync(new DifferentPoco { NotExists = "Foo" });
60+
Assert.Fail("Should throw");
61+
}
62+
catch (Exception ex)
63+
{
64+
Assert.That(ex.Message, Is.StringContaining("Id").Or.StringContaining("NotExists"));
65+
}
66+
67+
try
68+
{
69+
await db.InsertAllAsync(new[] {
70+
new DifferentPoco { NotExists = "Foo" },
71+
new DifferentPoco { NotExists = "Bar" }
72+
});
73+
Assert.Fail("Should throw");
74+
}
75+
catch (Exception ex)
76+
{
77+
var innerEx = ex.UnwrapIfSingleException();
78+
Assert.That(innerEx.Message, Is.StringContaining("Id").Or.StringContaining("NotExists"));
79+
}
80+
81+
try
82+
{
83+
await db.UpdateAllAsync(new[] {
84+
new DifferentPoco { NotExists = "Foo" },
85+
new DifferentPoco { NotExists = "Bar" }
86+
});
87+
Assert.Fail("Should throw");
88+
}
89+
catch (Exception ex)
90+
{
91+
var innerEx = ex.UnwrapIfSingleException();
92+
Assert.That(innerEx.Message, Is.StringContaining("Id").Or.StringContaining("NotExists"));
93+
}
94+
}
95+
}
96+
97+
[Alias("Poco")]
98+
public class DifferentPoco
99+
{
100+
public int Id { get; set; }
101+
public string NotExists { get; set; }
102+
}
103+
38104
[Test]
39105
public async Task Test_Thread_Affinity()
40106
{

0 commit comments

Comments
 (0)