From 256fb167483172b13eef2c694997bb9c26b3b014 Mon Sep 17 00:00:00 2001 From: Kirill Grachev Date: Mon, 24 Apr 2023 21:45:42 +0300 Subject: [PATCH] SNRK-57: Pretty exceptions --- .../space/kscience/snark/storage/s3/S3Directory.kt | 8 ++++---- .../space/kscience/snark/storage/s3/S3Root.kt | 14 ++++++-------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Directory.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Directory.kt index d972fed..4ca0587 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Directory.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Directory.kt @@ -28,12 +28,12 @@ internal class S3Directory( override suspend fun getSubdir(path: Path): S3Directory = S3Directory(client, bucketName, currentDir / path) - override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): S3Directory = run { + override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): S3Directory = if (!ignoreIfExists) { - throw IllegalArgumentException("could not check if directory exists") + TODO("could not check if directory exists") + } else { + S3Directory(client, bucketName, currentDir / dirname) } - S3Directory(client, bucketName, currentDir / dirname) - } override fun close() { } diff --git a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Root.kt b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Root.kt index 4625a8c..14f18bd 100644 --- a/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Root.kt +++ b/snark-storage-driver/src/main/kotlin/space/kscience/snark/storage/s3/S3Root.kt @@ -9,13 +9,11 @@ import java.lang.Exception import java.nio.file.Path import kotlin.io.path.* -public fun s3Storage(client: S3Client): Directory { - return S3Root(client) -} +public fun s3Storage(client: S3Client): Directory = + S3Root(client) -public fun s3Bucket(client: S3Client, bucket: String): Directory { - return S3Directory(client, bucket, Path("")) -} +public fun s3Bucket(client: S3Client, bucket: String): Directory = + S3Directory(client, bucket, Path("")) internal fun splitPathIntoBucketAndPath(path: Path): Pair { val bucket = path.getName(0) @@ -43,7 +41,7 @@ internal class S3Root(private val client: S3Client) : Directory { } S3Directory(client, bucketName, recentPath) } catch (ex: Exception) { - throw java.nio.file.AccessDeniedException(path.toString()).initCause(ex) + throw AccessDeniedException(path.toFile(), reason = ex.message) } override suspend fun createSubdir(dirname: String, ignoreIfExists: Boolean): Directory = try { @@ -53,7 +51,7 @@ internal class S3Root(private val client: S3Client) : Directory { } S3Directory(client, bucketName, recentPath) } catch (ex: Exception) { - throw java.nio.file.AccessDeniedException(dirname).initCause(ex) + throw AccessDeniedException(File(dirname), reason = ex.message) } override fun close() {