coil icon indicating copy to clipboard operation
coil copied to clipboard

Conflicting error extension function can lead to Unexpected Runtime Exceptions

Open itsusmon opened this issue 8 months ago • 1 comments

Is your feature request related to a problem? Please describe.

The name of the extension function error for the ImageRequest.Builder class is confusing. I'm using Coil in a view-based Android project. I was using the ImageView.load function inside of a fragment and would use error(@DrawableRes drawableResId: Int). But since it's an extension function, it requires importing. When I was writing code, the IDEA automatically imported the error(message: Any) function from Kotlin stdlib, which throws IllegalStateException and causes a runtime exception.

Describe the solution you'd like

Could the error function be renamed to onError? Or the library should include a lint check that warns the user when there is an error(message: Any) function (from stdlib) usage in the context of ImageRequest.Builder class.

itsusmon avatar Mar 12 '25 04:03 itsusmon

Yep this isn't ideal. Fortunately it only occurs with an implicit ImageRequest.Builder receiver which is only used with ImageView.load - not Compose.

I don't think we can rename error as it's heavily used and deprecating it will create a lot of warnings for users downstream. I think our best bet is to add a Lint check as you mentioned.

colinrtwhite avatar Mar 13 '25 16:03 colinrtwhite