Skip to content

breaking-change(plugin-svgo): handle potential errors from optimize#663

Merged
gregberge merged 2 commits into
gregberge:mainfrom
mikaelbr:svgo/error
Jan 9, 2022
Merged

breaking-change(plugin-svgo): handle potential errors from optimize#663
gregberge merged 2 commits into
gregberge:mainfrom
mikaelbr:svgo/error

Conversation

@mikaelbr

@mikaelbr mikaelbr commented Jan 7, 2022

Copy link
Copy Markdown
Contributor

Summary

svg.optimize() can in some cases return error, when passed SVG is invalid. There are some cases also, for instance when removing some namespace attributes that the SVG is invalid as a cause of that. When this happens data returned from plugin-svgo will be undefined, causing this to be undefined in the following iteration of the loop. This again causes obscure errors in some cases when running the following plugins.

This depends on fixing the types for svgo: DefinitelyTyped/DefinitelyTyped#58031

Note: Marked this as breaking-change as it explicitly throws an error. There are other ways to handle this (propagate error etc), but feels like showing error here is better than just ignoring it.

This PR does not fix consumers of plugin-svgo to handle error.

Test plan

Added test case to ensure invalid svg throws error.

@vercel

vercel Bot commented Jan 7, 2022

Copy link
Copy Markdown

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/gregberge/svgr/HNFpWhTxkXQNFjUPHCdnw4hV6KWy
✅ Preview: https://svgr-git-fork-mikaelbr-svgo-error-gregberge.vercel.app

@gregberge

Copy link
Copy Markdown
Owner

Hello @mikaelbr, I don't think it is a real breaking change here.

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

Successfully merging this pull request may close these issues.

2 participants