Skip to content

Commit c7664c9

Browse files
committed
Preserve original exception.
This may help with diagnosis of exceptions thrown from ActivateResultSet.
1 parent ad5a51a commit c7664c9

File tree

3 files changed

+22
-20
lines changed

3 files changed

+22
-20
lines changed

src/MySqlConnector/MySqlClient/MySqlDataReader.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections;
33
using System.Collections.Generic;
44
using System.Data;
@@ -70,7 +70,11 @@ internal async Task<bool> NextResultAsync(IOBehavior ioBehavior, CancellationTok
7070
private void ActivateResultSet(ResultSet resultSet)
7171
{
7272
if (resultSet.ReadResultSetHeaderException != null)
73-
throw resultSet.ReadResultSetHeaderException;
73+
{
74+
throw resultSet.ReadResultSetHeaderException is MySqlException mySqlException ?
75+
new MySqlException(mySqlException.Number, mySqlException.SqlState, mySqlException.Message, mySqlException) :
76+
resultSet.ReadResultSetHeaderException;
77+
}
7478

7579
Command.LastInsertedId = resultSet.LastInsertId;
7680
m_recordsAffected += resultSet.RecordsAffected;

tests/SideBySide/BulkLoaderAsync.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using System.Threading.Tasks;
@@ -149,16 +149,15 @@ public async Task BulkLoadCsvFileNotFound()
149149
{
150150
int rowCount = await bl.LoadAsync();
151151
}
152-
catch (MySqlException mySqlException)
152+
catch (Exception exception)
153153
{
154-
if (mySqlException.InnerException != null)
155-
{
156-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException.InnerException);
157-
}
158-
else
154+
while (exception.InnerException != null)
155+
exception = exception.InnerException;
156+
157+
if (!(exception is FileNotFoundException))
159158
{
160-
Assert.Contains("Errcode: 2 ", mySqlException.Message);
161-
Assert.Contains("No such file or directory", mySqlException.Message);
159+
Assert.Contains("Errcode: 2 ", exception.Message);
160+
Assert.Contains("No such file or directory", exception.Message);
162161
}
163162
}
164163
}

tests/SideBySide/BulkLoaderSync.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.IO;
33
using System.Linq;
44
using MySql.Data.MySqlClient;
@@ -151,16 +151,15 @@ public void BulkLoadCsvFileNotFound()
151151
{
152152
int rowCount = bl.Load();
153153
}
154-
catch (MySqlException mySqlException)
154+
catch (Exception exception)
155155
{
156-
if (mySqlException.InnerException != null)
157-
{
158-
Assert.IsType(typeof(System.IO.FileNotFoundException), mySqlException.InnerException);
159-
}
160-
else
156+
while (exception.InnerException != null)
157+
exception = exception.InnerException;
158+
159+
if (!(exception is FileNotFoundException))
161160
{
162-
Assert.Contains("Errcode: 2 ", mySqlException.Message);
163-
Assert.Contains("No such file or directory", mySqlException.Message);
161+
Assert.Contains("Errcode: 2 ", exception.Message);
162+
Assert.Contains("No such file or directory", exception.Message);
164163
}
165164
}
166165
}

0 commit comments

Comments
 (0)