From d50fd463ff3897ce6fb53b2913ef3f658aeac9ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Wa=C5=9B?= Date: Wed, 31 Jul 2024 09:48:18 +0200 Subject: [PATCH] Throw a better exception in Azure FS createOrOverwrite Throw FileNotFoundException instead of a BlobStorageException, since the latter doesn't extend IOException. This addresses a test failure missed in 1073b0836bf1fb560a3a4a664f67171f5047d086. --- .../io/trino/filesystem/azure/AzureOutputFile.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/trino-filesystem-azure/src/main/java/io/trino/filesystem/azure/AzureOutputFile.java b/lib/trino-filesystem-azure/src/main/java/io/trino/filesystem/azure/AzureOutputFile.java index 5d9d242112d2..52f17228945c 100644 --- a/lib/trino-filesystem-azure/src/main/java/io/trino/filesystem/azure/AzureOutputFile.java +++ b/lib/trino-filesystem-azure/src/main/java/io/trino/filesystem/azure/AzureOutputFile.java @@ -15,10 +15,13 @@ import com.azure.core.util.BinaryData; import com.azure.storage.blob.BlobClient; +import com.azure.storage.blob.models.BlobErrorCode; +import com.azure.storage.blob.models.BlobStorageException; import io.trino.filesystem.Location; import io.trino.filesystem.TrinoOutputFile; import io.trino.memory.context.AggregatedMemoryContext; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.OutputStream; import java.nio.file.FileAlreadyExistsException; @@ -69,7 +72,15 @@ public OutputStream create(AggregatedMemoryContext memoryContext) public void createOrOverwrite(byte[] data) throws IOException { - blobClient.getBlockBlobClient().upload(BinaryData.fromBytes(data), true); + try { + blobClient.getBlockBlobClient().upload(BinaryData.fromBytes(data), true); + } + catch (BlobStorageException e) { + if (BlobErrorCode.CONTAINER_NOT_FOUND.equals(e.getErrorCode())) { + throw new FileNotFoundException(location.toString()); + } + throw e; + } } @Override