From d0b004328e15069b63291108f6bc4f2d71c5a9fd Mon Sep 17 00:00:00 2001 From: Krzysztof Nozderko Date: Mon, 18 Nov 2024 11:04:42 +0100 Subject: [PATCH] SNOW-1805438 handle null data in failed responses --- .../UnitTests/SFStatementTest.cs | 32 ++++++++++++++++--- Snowflake.Data/Core/SFStatement.cs | 6 ++-- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs b/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs index 3f131e924..5d27c6add 100755 --- a/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs +++ b/Snowflake.Data.Tests/UnitTests/SFStatementTest.cs @@ -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 */ @@ -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(() => statement.BuildResultSet(response, CancellationToken.None)); + + // assert + Assert.AreEqual("Error: internal error SqlState: , VendorCode: 500, QueryId: ", thrown.Message); + } } } diff --git a/Snowflake.Data/Core/SFStatement.cs b/Snowflake.Data/Core/SFStatement.cs index 146a10130..7dac1c600 100644 --- a/Snowflake.Data/Core/SFStatement.cs +++ b/Snowflake.Data/Core/SFStatement.cs @@ -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)) { @@ -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)