diff --git a/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsAsyncClient.java b/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsAsyncClient.java index 166e22f73c72..4b37e92b240c 100644 --- a/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsAsyncClient.java +++ b/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsAsyncClient.java @@ -30,6 +30,8 @@ import com.azure.storage.blob.BlobClientBuilder; import com.azure.storage.blob.BlobContainerAsyncClient; import com.azure.storage.blob.BlobContainerClientBuilder; +import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; @@ -284,8 +286,10 @@ public Mono createDatasetWithFolder(String name, String ve String relativePath = folderPath.relativize(filePath).toString().replace('\\', '/'); return containerClient.getBlobAsyncClient(relativePath).upload(BinaryData.fromFile(filePath), true); }).then(Mono.just(containerUrl)); - } catch (Exception e) { - return Mono.error(new RuntimeException("Error walking through folder path", e)); + } catch (IOException e) { + return Mono.error(new UncheckedIOException("Failed to walk folder path: " + folderPath, e)); + } catch (RuntimeException e) { + return Mono.error(e); } }).flatMap(containerUrl -> { RequestOptions requestOptions = new RequestOptions(); diff --git a/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsClient.java b/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsClient.java index 6be6591b8b92..d477449559c6 100644 --- a/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsClient.java +++ b/sdk/ai/azure-ai-projects/src/main/java/com/azure/ai/projects/DatasetsClient.java @@ -30,6 +30,7 @@ import com.azure.storage.blob.BlobContainerClient; import com.azure.storage.blob.BlobContainerClientBuilder; import java.io.IOException; +import java.io.UncheckedIOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.stream.Stream; @@ -226,11 +227,10 @@ public FileDatasetVersion createDatasetWithFile(String name, String version, Pat * @param folderPath The path to the folder containing files to upload. * @return A FolderDatasetVersion representing the created dataset. * @throws IllegalArgumentException If the provided path is not a directory. - * @throws IOException if an I/ O error is thrown when accessing the starting file + * @throws UncheckedIOException if an I/ O error is thrown when accessing the starting file */ @ServiceMethod(returns = ReturnType.SINGLE) - public FolderDatasetVersion createDatasetWithFolder(String name, String version, Path folderPath) - throws IOException { + public FolderDatasetVersion createDatasetWithFolder(String name, String version, Path folderPath) { return createDatasetWithFolder(name, version, folderPath, null); } @@ -244,11 +244,11 @@ public FolderDatasetVersion createDatasetWithFolder(String name, String version, * If null, the default Azure Storage Account connection will be used. * @return A FolderDatasetVersion representing the created dataset. * @throws IllegalArgumentException If the provided path is not a directory. - * @throws IOException if an I/O error is thrown when accessing the starting file + * @throws UncheckedIOException if an I/O error is thrown when accessing the starting file */ @ServiceMethod(returns = ReturnType.SINGLE) public FolderDatasetVersion createDatasetWithFolder(String name, String version, Path folderPath, - String connectionName) throws IOException { + String connectionName) { if (!Files.isDirectory(folderPath)) { throw LOGGER .logExceptionAsError(new IllegalArgumentException("The provided path is not a folder: " + folderPath)); @@ -268,6 +268,8 @@ public FolderDatasetVersion createDatasetWithFolder(String name, String version, String relativePath = folderPath.relativize(filePath).toString().replace('\\', '/'); containerClient.getBlobClient(relativePath).upload(BinaryData.fromFile(filePath), true); }); + } catch (IOException e) { + throw LOGGER.logExceptionAsError(new UncheckedIOException("Failed to walk folder path: " + folderPath, e)); } RequestOptions requestOptions = new RequestOptions(); FolderDatasetVersion datasetVersion = this