Skip to content

Commit

Permalink
SNOW-950923 QueryID for PUT/GET without changes to the related except…
Browse files Browse the repository at this point in the history
…ions
  • Loading branch information
sfc-gh-mhofman committed Dec 6, 2023
1 parent 4aae56e commit 13d1106
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 55 deletions.
5 changes: 2 additions & 3 deletions Snowflake.Data.Tests/IntegrationTests/SFPutGetTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,9 @@ string PutFile(
}
Assert.IsNull(reader.GetString((int)SFResultSet.PutGetResponseRowTypeInfo.ErrorDetails));
}
catch (SnowflakeDbException e)
catch (Exception e)
{
queryId = e.QueryId;
Assert.AreEqual(queryId, ((SnowflakeDbCommand)command).GetQueryId());
queryId = ((SnowflakeDbCommand)command).GetQueryId();
}
}
return queryId;
Expand Down
27 changes: 7 additions & 20 deletions Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
* Copyright (c) 2012-2023 Snowflake Computing Inc. All rights reserved.
*/

using Amazon.S3.Transfer;
using Snowflake.Data.Client;

namespace Snowflake.Data.Tests.UnitTests
{
using NUnit.Framework;
Expand Down Expand Up @@ -490,17 +487,15 @@ public void TestUploadThrowsArgumentExceptionForMissingRootDirectoryWithWildcard

// Set command to upload
_responseData.command = CommandTypes.UPLOAD.ToString();
_responseData.queryId = Guid.NewGuid().ToString();
_fileTransferAgent = new SFFileTransferAgent(_putQuery,
_session,
_responseData,
_cancellationToken);

// Act
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _fileTransferAgent.execute());
Exception ex = Assert.Throws<ArgumentException>(() => _fileTransferAgent.execute());

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
Assert.That(ex.Message, Does.Match($"No file found for: {tempUploadRootDirectory}\\*/{tempUploadSecondDirectory}\\*/{mockFileName}"));

for (int i = 0; i < numberOfDirectories; i++)
Expand Down Expand Up @@ -584,21 +579,17 @@ public void TestDownloadThrowsErrorFileNotFound()

// Set command to download
_responseData.command = CommandTypes.DOWNLOAD.ToString();
_responseData.queryId = Guid.NewGuid().ToString();
_fileTransferAgent = new SFFileTransferAgent(GetQuery,
_session,
_responseData,
_cancellationToken);

// Act
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _fileTransferAgent.execute());
Exception ex = Assert.Throws<AggregateException>(() => _fileTransferAgent.execute());

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
Assert.IsInstanceOf<AggregateException>(ex.InnerException);
var innerException = ((AggregateException)ex.InnerException)?.InnerExceptions[0];
Assert.IsInstanceOf<FileNotFoundException>(innerException);
Assert.That(innerException?.Message, Does.Match("Could not find file .*"));
Assert.IsInstanceOf<FileNotFoundException>(ex.InnerException);
Assert.That(ex.InnerException.Message, Does.Match("Could not find file .*"));
}

[Test]
Expand All @@ -615,21 +606,17 @@ public void TestDownloadThrowsErrorDirectoryNotFound()

// Set command to download
_responseData.command = CommandTypes.DOWNLOAD.ToString();
_responseData.queryId = Guid.NewGuid().ToString();
_fileTransferAgent = new SFFileTransferAgent(GetQuery,
_session,
_responseData,
_cancellationToken);

// Act
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _fileTransferAgent.execute());
Exception ex = Assert.Throws<AggregateException>(() => _fileTransferAgent.execute());

// Assert
Assert.AreEqual(_responseData.queryId, ex.QueryId);
Assert.IsInstanceOf<AggregateException>(ex.InnerException);
var innerException = ((AggregateException)ex.InnerException)?.InnerExceptions[0];
Assert.IsInstanceOf<DirectoryNotFoundException>(innerException);
Assert.That(innerException?.Message, Does.Match("Could not find a part of the path .*"));
Assert.IsInstanceOf<DirectoryNotFoundException>(ex.InnerException);
Assert.That(ex.InnerException.Message, Does.Match("Could not find a part of the path .*"));
}
}
}
9 changes: 1 addition & 8 deletions Snowflake.Data/Client/SnowflakeDbException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public sealed class SnowflakeDbException : DbException

private int VendorCode;

public string QueryId { get; set; }
public string QueryId { get; }

public override int ErrorCode
{
Expand All @@ -45,13 +45,6 @@ public SnowflakeDbException(string sqlState, int vendorCode, string errorMessage
QueryId = queryId;
}

public SnowflakeDbException(SFError error, string queryId, Exception innerException)
: base(FormatExceptionMessage(error, new object[] {innerException.Message}, string.Empty, queryId), innerException)
{
VendorCode = error.GetAttribute<SFErrorAttr>().errorCode;
QueryId = queryId;
}

public SnowflakeDbException(SFError error, params object[] args)
: base(FormatExceptionMessage(error, args, string.Empty, string.Empty))
{
Expand Down
5 changes: 1 addition & 4 deletions Snowflake.Data/Core/ErrorMessages.resx
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,4 @@
<data name="BROWSER_RESPONSE_TIMEOUT" xml:space="preserve">
<value>Browser response timed out after {0} seconds.</value>
</data>
<data name="IO_ERROR_ON_GETPUT_COMMAND" xml:space="preserve">
<value>IO operation failed. Error: {0}</value>
</data>
</root>
</root>
10 changes: 1 addition & 9 deletions Snowflake.Data/Core/FileTransfer/SFFileTransferAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,7 @@ public void execute()
catch (Exception e)
{
Logger.Error("Error while transferring file(s): " + e.Message);
if (e is SnowflakeDbException snowflakeException)
{
if (snowflakeException.QueryId == null)
{
snowflakeException.QueryId = TransferMetadata.queryId;
}
throw snowflakeException;
}
throw new SnowflakeDbException(SFError.IO_ERROR_ON_GETPUT_COMMAND, TransferMetadata.queryId, e);
throw;
}

}
Expand Down
3 changes: 0 additions & 3 deletions Snowflake.Data/Core/SFError.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,6 @@ public enum SFError

[SFErrorAttr(errorCode = 270057)]
BROWSER_RESPONSE_TIMEOUT,

[SFErrorAttr(errorCode = 270058)]
IO_ERROR_ON_GETPUT_COMMAND
}

class SFErrorAttr : Attribute
Expand Down
11 changes: 3 additions & 8 deletions Snowflake.Data/Core/SFStatement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,16 +357,16 @@ internal SFBaseResultSet Execute(int timeout, string sql, Dictionary<string, Bin
describeOnly);

logger.Debug("PUT/GET queryId: " + (response.data != null ? response.data.queryId : "Unknown"));

if (response.data != null)
_lastQueryId = response.data.queryId;

SFFileTransferAgent fileTransferAgent =
new SFFileTransferAgent(trimmedSql, SfSession, response.data, CancellationToken.None);

// Start the file transfer
fileTransferAgent.execute();

if (response.data != null)
_lastQueryId = response.data.queryId;

// Get the results of the upload/download
return fileTransferAgent.result();
}
Expand Down Expand Up @@ -412,11 +412,6 @@ internal SFBaseResultSet Execute(int timeout, string sql, Dictionary<string, Bin
catch (Exception ex)
{
logger.Error("Query execution failed.", ex);
if (ex is SnowflakeDbException)
{
var snowflakeDbException = (SnowflakeDbException)ex;
this._lastQueryId = snowflakeDbException.QueryId;
}
throw;
}
finally
Expand Down

0 comments on commit 13d1106

Please sign in to comment.