Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SVG errors not surfaced in onError callback #2798

Open
jocmp opened this issue Jan 21, 2025 · 4 comments
Open

SVG errors not surfaced in onError callback #2798

jocmp opened this issue Jan 21, 2025 · 4 comments

Comments

@jocmp
Copy link

jocmp commented Jan 21, 2025

Describe the bug

I author an RSS reader that integrates with a service called FreshRSS. FreshRSS sometimes selects a website's SVG favicon to display as an icon via their API. In most cases, websites use simple SVGs. However some cases like the one below, the SVG may contain CSS that cannot be parsed by Coil.

For example, SVGs that contain media queries error but don't call the onError callback. Given the following test SVG (https://www.faz.net/favicon.svg) that includes this CSS, the SVG is not displayed.

    path {
    fill: #212529;

    @media (prefers-color-scheme: dark) {
    fill: #FFFFFF;
    }
    }

Image

This is a noted constraint in the underlying SVG library on Android (BigBadaboom/androidsvg#231) and errors on the ruleset with the following error.

CSS parser terminated early due to error: Expected ':'

Ideally the final SVG would be rendered correctly or at least call onError so the app code can react correctly.

To Reproduce

Create an AsyncImage and pass the hardcoded URL of "https://www.faz.net/favicon.svg" as the data argument.

  AsyncImage(
    "https://www.faz.net/favicon.svg",
    contentDescription = "",
    onError = {
        Log.d("MY_TAG", it.result.throwable.toString())
    }
)

In my testing, onError is never called.

Version
coil 2.7.0, coil-svg 2.7.0. I have not tried this on Coil 3.

@colinrtwhite
Copy link
Member

Is it possible to detect that a parsing exception has occurred? According to the code snippet you linked it looks like the library catches those exceptions and only calls Log.e.

@jocmp
Copy link
Author

jocmp commented Jan 22, 2025

Not to my knowledge. When the error occurs internally the ruleset variable is set to null. This is not necessarily an error since style in an SVG is optional.

I put together a simplified demo project (https://github.com/jocmp/svgdebug) to display the difference in output for the library between the SVG with the media selector and without it. The SVG without the media selector displays correctly in a red box.

@colinrtwhite
Copy link
Member

Thanks for the repro project. I agree we should ideally report the parsing issue to onError in this case, however it doesn't seem to be possible with how https://github.com/BigBadaboom/androidsvg handles the error. Given that I'm not sure there's anything we can do in Coil to pass through the parsing exception.

@jocmp
Copy link
Author

jocmp commented Jan 22, 2025

Makes sense. Out of curiosity, are there other SVG libraries for Android you've seen? I noticed Glide also uses androidsvg but the library hasn't had a release in 4 years.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants