SNRK-57: Pretty exceptions

This commit is contained in:
Kirill Grachev 2023-04-24 21:45:42 +03:00
parent d292abc816
commit 256fb16748
2 changed files with 10 additions and 12 deletions

View File

@ -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() {
}

View File

@ -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<String, Path> {
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() {