I want to validate a filepath to a sqlite database...
# getting-started
k
I want to validate a filepath to a sqlite database and provide helpful feedback, is this an appropriate way to accomplish this?
Copy code
return when {
    filename.isNullOrBlank() -> context.error("Cannot be blank")
    !File(filename).exists() -> context.error("File does not exist")
    !File(filename).isFile -> context.error("Not a file")
    !File(filename).canRead() -> context.error("Permission Denied")
    else -> when (val code = canConnect(filename)) {
        SQLiteErrorCode.SQLITE_OK -> context.success()
        else -> context.error(code.message)
    }
}
I only want to try to open a JDBC connection once I know it’s a valid filepath and all that, but is nesting a
when
inside the
else
of another
when
bad form?
k
I wouldn't consider nesting `when`s bad form.