Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SNOW-1805438 Handle null data in failed responses #1061

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading