SNRK-57: Pretty exceptions
This commit is contained in:
parent
d292abc816
commit
256fb16748
@ -28,12 +28,12 @@ internal class S3Directory(
|
|||||||
override suspend fun getSubdir(path: Path): S3Directory =
|
override suspend fun getSubdir(path: Path): S3Directory =
|
||||||
S3Directory(client, bucketName, currentDir / path)
|
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) {
|
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() {
|
override fun close() {
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,11 @@ import java.lang.Exception
|
|||||||
import java.nio.file.Path
|
import java.nio.file.Path
|
||||||
import kotlin.io.path.*
|
import kotlin.io.path.*
|
||||||
|
|
||||||
public fun s3Storage(client: S3Client): Directory {
|
public fun s3Storage(client: S3Client): Directory =
|
||||||
return S3Root(client)
|
S3Root(client)
|
||||||
}
|
|
||||||
|
|
||||||
public fun s3Bucket(client: S3Client, bucket: String): Directory {
|
public fun s3Bucket(client: S3Client, bucket: String): Directory =
|
||||||
return S3Directory(client, bucket, Path(""))
|
S3Directory(client, bucket, Path(""))
|
||||||
}
|
|
||||||
|
|
||||||
internal fun splitPathIntoBucketAndPath(path: Path): Pair<String, Path> {
|
internal fun splitPathIntoBucketAndPath(path: Path): Pair<String, Path> {
|
||||||
val bucket = path.getName(0)
|
val bucket = path.getName(0)
|
||||||
@ -43,7 +41,7 @@ internal class S3Root(private val client: S3Client) : Directory {
|
|||||||
}
|
}
|
||||||
S3Directory(client, bucketName, recentPath)
|
S3Directory(client, bucketName, recentPath)
|
||||||
} catch (ex: Exception) {
|
} 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 {
|
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)
|
S3Directory(client, bucketName, recentPath)
|
||||||
} catch (ex: Exception) {
|
} catch (ex: Exception) {
|
||||||
throw java.nio.file.AccessDeniedException(dirname).initCause(ex)
|
throw AccessDeniedException(File(dirname), reason = ex.message)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun close() {
|
override fun close() {
|
||||||
|
Loading…
Reference in New Issue
Block a user