Skip to content

Commit

Permalink
SNOW-950923 changed type of exception thrown when directory/file not …
Browse files Browse the repository at this point in the history
…found to provide QueryID (potential BCR)
  • Loading branch information
sfc-gh-mhofman committed Dec 6, 2023
1 parent b9661c9 commit 4aae56e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
27 changes: 20 additions & 7 deletions Snowflake.Data.Tests/UnitTests/SFFileTransferAgentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
* 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 @@ -487,15 +490,17 @@ 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
Exception ex = Assert.Throws<ArgumentException>(() => _fileTransferAgent.execute());
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _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 @@ -579,17 +584,21 @@ 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
Exception ex = Assert.Throws<AggregateException>(() => _fileTransferAgent.execute());
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _fileTransferAgent.execute());

// Assert
Assert.IsInstanceOf<FileNotFoundException>(ex.InnerException);
Assert.That(ex.InnerException.Message, Does.Match("Could not find file .*"));
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 .*"));
}

[Test]
Expand All @@ -606,17 +615,21 @@ 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
Exception ex = Assert.Throws<AggregateException>(() => _fileTransferAgent.execute());
SnowflakeDbException ex = Assert.Throws<SnowflakeDbException>(() => _fileTransferAgent.execute());

// Assert
Assert.IsInstanceOf<DirectoryNotFoundException>(ex.InnerException);
Assert.That(ex.InnerException.Message, Does.Match("Could not find a part of the path .*"));
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 .*"));
}
}
}
2 changes: 1 addition & 1 deletion Snowflake.Data/Client/SnowflakeDbException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public SnowflakeDbException(string sqlState, int vendorCode, string errorMessage
}

public SnowflakeDbException(SFError error, string queryId, Exception innerException)
: base(FormatExceptionMessage(error, new object[] {innerException.Message}, string.Empty, queryId))
: base(FormatExceptionMessage(error, new object[] {innerException.Message}, string.Empty, queryId), innerException)
{
VendorCode = error.GetAttribute<SFErrorAttr>().errorCode;
QueryId = queryId;
Expand Down
10 changes: 0 additions & 10 deletions Snowflake.Data/Core/FileTransfer/SFFileTransferAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,16 +228,6 @@ public void execute()
download();
}
}
catch (FileNotFoundException e)
{
Logger.Error("File not found while transferring file(s): " + e.Message);
throw new SnowflakeDbException(SFError.IO_ERROR_ON_GETPUT_COMMAND, TransferMetadata.queryId, e);
}
catch (IOException e)
{
Logger.Error("IO operation error while transferring file(s): " + e.Message);
throw new SnowflakeDbException(SFError.IO_ERROR_ON_GETPUT_COMMAND, TransferMetadata.queryId, e);
}
catch (Exception e)
{
Logger.Error("Error while transferring file(s): " + e.Message);
Expand Down

0 comments on commit 4aae56e

Please sign in to comment.