I wonder if Konsist could be the right tool to hel...
# konsist
t
I wonder if Konsist could be the right tool to help detect potential unhandled exceptions in certain layers. For example, a ViewModel that, tracing the call hierarchy, doesn’t handle a network exception..
p
I think currently it is not supported to check for exceptions that are thrown by a function. The only possibility is to assert the function text which is not very comfortable.
i
Konsist does not allow to verify function structure, however you can check imports for given class:
Copy code
Konsist
.scopeFromProduction()
.classes()
.withParentClassOf(ViewModel::class)
.assertTrue {
                   it.containingFile.hasImport { import -> import.name == "com.NetworkException" }
                    //or
                   it.containingFile.hasImport { import -> import.representsTypeOf<NetworkException>() }
                }
Assuming no unused imports are present in the file this should work (AS/IDEA
autoImport
feature should help)
👍 1
p
Ah... import checking I did not think about. that's a good option 👍