Skip to content

Commit

Permalink
SNOW-1805438 Handle null data in failed responses (#1061)
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-knozderko authored Nov 19, 2024
1 parent 05da00a commit 296a281
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
32 changes: 27 additions & 5 deletions Snowflake.Data.Tests/UnitTests/SFStatementTest.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
/*
* Copyright (c) 2012-2019 Snowflake Computing Inc. All rights reserved.
* Copyright (c) 2012-2024 Snowflake Computing Inc. All rights reserved.
*/

using System.Threading;
using Snowflake.Data.Client;
using Snowflake.Data.Core;
using NUnit.Framework;
using System;

namespace Snowflake.Data.Tests.UnitTests
{
using Snowflake.Data.Core;
using NUnit.Framework;
using System;

/**
* Mock rest request test
*/
Expand Down Expand Up @@ -191,5 +193,25 @@ public void TestIsAnError(QueryStatus status, bool expectedResult)
{
Assert.AreEqual(expectedResult, QueryStatusExtensions.IsAnError(status));
}

[Test]
public void TestHandleNullDataForFailedResponse()
{
// arrange
var response = new QueryExecResponse
{
success = false,
code = 500,
message = "internal error"
};
var session = new SFSession("account=myAccount;password=myPassword;user=myUser;db=myDB", null);
var statement = new SFStatement(session);

// act
var thrown = Assert.Throws<SnowflakeDbException>(() => statement.BuildResultSet(response, CancellationToken.None));

// assert
Assert.AreEqual("Error: internal error SqlState: , VendorCode: 500, QueryId: ", thrown.Message);
}
}
}
6 changes: 3 additions & 3 deletions Snowflake.Data/Core/SFStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ private void CleanUpCancellationTokenSources()
}
}

private SFBaseResultSet BuildResultSet(QueryExecResponse response, CancellationToken cancellationToken)
internal SFBaseResultSet BuildResultSet(QueryExecResponse response, CancellationToken cancellationToken)
{
if ((response.data != null) && (response.data.queryId != null))
{
Expand All @@ -308,8 +308,8 @@ private SFBaseResultSet BuildResultSet(QueryExecResponse response, CancellationT
}
}

throw new SnowflakeDbException(response.data.sqlState,
response.code, response.message, response.data.queryId);
throw new SnowflakeDbException(response.data?.sqlState,
response.code, response.message, response.data?.queryId);
}

private void SetTimeout(int timeout)
Expand Down

0 comments on commit 296a281

Please sign in to comment.