Skip to content

[Icons] Add ignore_not_found config option #2023

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

Merged
merged 1 commit into from
Aug 7, 2024

Conversation

smnandre
Copy link
Member

@smnandre smnandre commented Aug 1, 2024

Q A
Bug fix? no
New feature? yes
Issues Fix #2008
License MIT

Allow to silence error during rendering when an icon is not found (then a warning is log)

@carsonbot carsonbot added Status: Needs Work Additional work is needed and removed Status: Needs Review Needs to be reviewed labels Aug 2, 2024
@@ -58,6 +58,10 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->end()
->end()
->booleanNode('ignore_not_found')
->info('Ignore error when an icon is not found.')
->defaultFalse()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could default to %kernel.debug% here or in the recipe

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the idea in #2008 was to default to "not kernel.debug".

I this change anything in prod, in would be a BC break, so maybe the recipe is a good solution, indeed

try {
return $this->iconRenderer->renderIcon($name, $attributes);
} catch (IconNotFoundException $e) {
if ($this->ignoreNotFound) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's a Twig rendering context, I'm wondering if we should use Environment::isStrictVariables() instead. I can't picture a case where the twig.strict_variables config is different from ux_icons.ignoreNotFound. They serve the same purpose for me.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking this also, at least until we're asked for a separate config option.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If by "using Environment::isStrictVariables()" you mean "do not throw if strictVariable = false", this would be a BC break, no ?

Copy link
Member

@yceruto yceruto Aug 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not throwing the exception in the prod env doesn't seem like a critical behavior change to me. In fact, that's exactly what the reporter is requesting (aligned with how Twig behaves). As suggested #2023 (comment) we could log the error instead.

The configs (strict_variables and ignore_not_found) appear to be opposite due to their naming, but they actually represent the same concept/purpose.

@carsonbot carsonbot added Status: Needs Review Needs to be reviewed and removed Status: Needs Work Additional work is needed labels Aug 2, 2024
@smnandre
Copy link
Member Author

smnandre commented Aug 2, 2024

Update: add a logger / log a warning when icon is not found

@smnandre
Copy link
Member Author

smnandre commented Aug 2, 2024

@kbond @yceruto

--

I've been -more than once- told we cannot do this or that for way, way smaller BC breaks.

But if you guys say it's ok, that's ok for me.

--

ignore_missing exist in Twig (include, source) too. It was my inspiration here for the name ... and felt very similar

Every other filter / function i know of throw in Twig when an error occurs

The only silent thing is for getAttribute.

To me an icon (which should be in cache) is nothing like an attribute on an (existing) object.

The asset function throw when an asset does not exist (example: a svg icon)

--

If we use strict_variables here, I cannot have exception in prod for missing icons anymore.

(i would need to set strict_variables to true -- something i don't desire for obvious reasons)

--

Not in the mood for the subtext of this discussion.. so just tell me your decision and i'll update the PR.

@kbond kbond force-pushed the feat/ignore-not-found branch from 8109a58 to 2dea170 Compare August 7, 2024 13:07
@kbond
Copy link
Member

kbond commented Aug 7, 2024

This looks fine to me as is!

@kbond kbond merged commit 1b4c6b3 into symfony:2.x Aug 7, 2024
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature New Feature Icons Status: Needs Review Needs to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ux_icon triggers an exception when icon doesn't exists
5 participants