Skip to content

Rule to ensure callee of function returning Try<Foo, Throwable> handles the throwable #3536

Answered by cortinico
efenderbosch asked this question in Q&A
Discussion options

You must be logged in to vote

Which of the visit... functions would be a good place to start to implement a Rule to fail on use of function returning a Try<Foo, Throwable> and the callee not handling the Throwable?

To answer your question, visitCallExpression is the correct function. You can take inspiration from the ForbiddenMethodCall rule:

private fun check(expression: KtExpression) {
if (bindingContext == BindingContext.EMPTY) return
val resolvedCall = expression.getResolvedCall(bindingContext) ?: return
val methodName = resolvedCall.resultingDescripto…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@efenderbosch
Comment options

Answer selected by schalkms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants