bigbone icon indicating copy to clipboard operation
bigbone copied to clipboard

Introduce client-side validation on methods

Open PattaFeuFeu opened this issue 8 months ago • 2 comments

In #287 and #286, I started introducing client-side validation for some very easy to catch errors defined by the Mastodon documentation, such as “input length should only be 80 characters”, “input should not contain spaces”, “input should not contain #”, and so on.

We want to go through all existing methods (“methods” meaning the methods in bigbone/src/main/kotlin/social/bigbone/api/method) and check where it could make sense to add client-side validation.

For the client-side validation, we want to return IllegalArgumentExceptions. For easy ones, we should use Kotlin’s require and a message lambda that we pass.

Example:

fun blockDomain(
    domain: String
) {
    require(domain.isNotBlank()) { "domain must not be blank" }

For the slightly harder ones where we deal with optional parameters that may or may not be null, but if they’re non-null need to follow certain criteria, we write our own checks, such as:

if (range.limit != null && range.limit > QUERY_RESULT_LIMIT) {
    throw IllegalArgumentException(
        "limit defined in Range must not be higher than $QUERY_RESULT_LIMIT but was ${range.limit}"
    )
}

@PattaFeuFeu I think we should go through all methods and implement these checks everywhere where needed. Let's create a separate issue for this. Any objections?

Originally posted by @andregasser in https://github.com/andregasser/bigbone/pull/287#discussion_r1367795877

PattaFeuFeu avatar Oct 21 '23 20:10 PattaFeuFeu