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

fix: warnings modperl_error_log #10344

Merged
merged 5 commits into from
Jun 4, 2024
Merged

Conversation

benbenben2
Copy link
Collaborator

What

attempt to fix warnings modperl_error_log

I believe it should fix

106	-e: Use of uninitialized value $title in concatenation (.) or string at /srv/off/lib/ProductOpener/Display.pm line 1481.
122	-e: Use of uninitialized value $code in pattern match (m//) at /srv/off/lib/ProductOpener/Products.pm line 412.
126	-e: Argument "" isn't numeric in numeric gt (>) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 57.
126	-e: Argument "" isn't numeric in numeric le (<=) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 40.
126	-e: Argument "" isn't numeric in numeric gt (>) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 45.
138	-e: Use of uninitialized value in numeric le (<=) at /srv/off/lib/ProductOpener/KnowledgePanels.pm line 1117.
162	-e: Wide character (U+6210) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
174	-e: Wide character (U+5206) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
184	-e: Invalid conversion in sprintf: end of string at /srv/off/lib/ProductOpener/Display.pm line 9017. -> 9050 (+43)
191	-e: Argument "" isn't numeric in division (/) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 92.
223	-e: Argument "" isn't numeric in division (/) at /srv/off/templates/api/knowledge-panels/environment/origins_of_ingredients.tt.json line 88.
229	-e: Argument "" isn't numeric in numeric le (<=) at /srv/off/templates/api/knowledge-panels/environment/origins_of_ingredients.tt.json line 50.
393	-e: Use of uninitialized value $canon_tag in string eq at /srv/off/lib/ProductOpener/Tags.pm line 3448.
393	-e: Use of uninitialized value $tag in ucfirst at /srv/off/lib/ProductOpener/Tags.pm line 3450.
393	-e: Use of uninitialized value $canon_tag in substitution (s///) at /srv/off/lib/ProductOpener/Tags.pm line 3449.
486	-e: Use of uninitialized value $canon_tag in substitution (s///) at /srv/off/lib/ProductOpener/Tags.pm line 3434.
486	-e: Use of uninitialized value $canon_tag in substitution (s///) at /srv/off/lib/ProductOpener/Tags.pm line 3433.
507	-e: Argument "" isn't numeric in multiplication (*) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 92.
556	-e: Argument "" isn't numeric in numeric gt (>) at /srv/off/templates/web/pages/product/includes/ecoscore_details.tt.html line 168.
718	-e: Argument "" isn't numeric in multiplication (*) at /srv/off/templates/api/knowledge-panels/environment/origins_of_ingredients.tt.json line 88.
815	-e: Use of uninitialized value $number_of_units in concatenation (.) or string at /srv/off/lib/ProductOpener/Products.pm line 2340.
4507	-e: Use of uninitialized value $ingredients_text_lc in hash element at /srv/off/lib/ProductOpener/KnowledgePanels.pm line 1298.
5049	-e: Argument "" isn't numeric in numeric lt (<) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/threatened_species.tt.json line 30.
6743	-e: Argument "" isn't numeric in addition (+) at /srv/off/templates/api/knowledge-panels/environment/ecoscore/total.tt.json line 1.
12333	-e: Use of uninitialized value in numeric ne (!=) at /srv/off/lib/ProductOpener/KnowledgePanels.pm line 709.

While following should remain:

114	-e: Wide character (U+E2A) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
189	zzz lc: es - request_ref->lc: es
199	-e: Use of uninitialized value in concatenation (.) or string at /srv/off/lib/ProductOpener/Display.pm line 8229.
231	-e: Wide character (U+8425) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
233	-e: Wide character (U+6570) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
248	-e: Use of uninitialized value in string eq at /srv/off/lib/ProductOpener/Display.pm line 9532.
257	-e: Use of uninitialized value in concatenation (.) or string at /srv/off/lib/ProductOpener/Display.pm line 8158.
270	-e: Wide character (U+6DFB) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
292	-e: Use of uninitialized value $ProductOpener::Display::User_id in string eq at /srv/off/lib/ProductOpener/Display.pm line 4055.
302	-e: Wide character (U+645) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
321	-e: Wide character (U+17A) in ucfirst at /usr/local/lib/x86_64-linux-gnu/perl/5.32.1/Template/Filters.pm line 57.
423	zzz lc: de - request_ref->lc: de
688	-e: Use of uninitialized value in concatenation (.) or string at /srv/off/lib/ProductOpener/Display.pm line 10894.
819	zzz lc: fr - request_ref->lc: fr
840	-e: Use of uninitialized value in pattern match (m//) at /srv/off/lib/ProductOpener/Display.pm line 10254.
934	-e: Use of uninitialized value $ingredients_text_lang in string ne at /srv/off/lib/ProductOpener/Display.pm line 7874.
934	-e: Use of uninitialized value $ingredients_text_lang in hash element at /srv/off/lib/ProductOpener/Display.pm line 7876.
1425	zzz lc: en - request_ref->lc: en
1553	-e: Use of uninitialized value $user_agent_str in pattern match (m//) at /srv/off/lib/ProductOpener/Display.pm line 984.
2568	zzz lc: zh - request_ref->lc: zh
5435	-e: Use of uninitialized value in numeric le (<=) at /srv/off/lib/ProductOpener/Display.pm line 5355.
5442	-e: Use of uninitialized value in subroutine argument at /srv/off/lib/ProductOpener/Tags.pm line 4134.
5507	-e: Use of uninitialized value in uc at /srv/off/lib/ProductOpener/Display.pm line 7642.
6189	-e: Argument "" isn't numeric in sprintf at /srv/off/lib/ProductOpener/Display.pm line 453.
8921	-e: Use of uninitialized value $ingredients_text_lc in concatenation (.) or string at /srv/off/lib/ProductOpener/Display.pm line 10939.
15985	-e: Use of uninitialized value in uc at /srv/off/lib/ProductOpener/Display.pm line 8789.

@stephanegigandet:

  • how can I generate the same log that you showed in the issue?
  • how can I test locally that I got rid of these wanings.

Related issue(s) and discussion

@benbenben2 benbenben2 self-assigned this May 23, 2024
@benbenben2 benbenben2 requested a review from a team as a code owner May 23, 2024 20:24
@github-actions github-actions bot added 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🌱 Eco-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products 📍 Origins Origins are used for Eco-Score computation. We want to have structured origins. Display Products Tags labels May 23, 2024
@@ -1,4 +1,27 @@
[% SET sum_of_bonuses_and_maluses = product.ecoscore_data.adjustments.production_system.value + product.ecoscore_data.adjustments.packaging.value + product.ecoscore_data.adjustments.threatened_species.value + product.ecoscore_data.adjustments.origins_of_ingredients.value %]
[% USE sum_of_bonuses_and_maluses = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think that work because if some adjusments are set, and others are not, you will sum the same value multiple times.

But ou can replace this whole part by just this:

					[% SET sum_of_bonuses_and_maluses = (product.ecoscore_data.adjustments.production_system.value || 0) + (product.ecoscore_data.adjustments.packaging.value || 0) + (product.ecoscore_data.adjustments.threatened_species.value || 0) + (product.ecoscore_data.adjustments.origins_of_ingredients.value || 0) %]

This suppresses the warnings.

@stephanegigandet
Copy link
Contributor

Thank you @benbenben2 !

  • how can I generate the same log that you showed in the issue?

It's the log over all queries on the production site.

  • how can I test locally that I got rid of these wanings.

The best way would be to first replicate it locally (by loading the page that you think triggers it, possibly crafting a special product with specific values), and then see if the warning is removed after.

Locally you can see the log here:

~/openfoodfacts-server/logs/apache2$ tail -f modperl_error_log

@@ -25,11 +25,11 @@
}
},
[% ELSE %]
[% IF product.ecoscore_data.adjustments.origins_of_ingredients.value <= 0 %]
[% IF defined product.ecoscore_data.adjustments.origins_of_ingredients.value && product.ecoscore_data.adjustments.origins_of_ingredients.value <= 0 %]
Copy link
Contributor

Choose a reason for hiding this comment

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

There's an error in the template:

( DIAG ) job 63 failed to fetch template: file error - parse error - api/knowledge-panels/environment/ecoscore/origins_of_ingredients.tt.json line 28: unexpected token (product)

Copy link
Contributor

Choose a reason for hiding this comment

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

You can't do [% IF defined something && something <= 0 %] in a template, but instead [% IF something.defined && something <= 0 %]

@@ -1334,7 +1339,11 @@ sub create_ingredients_panel ($product_ref, $target_lc, $target_cc, $options_ref
title => $title,
ingredients_text => $ingredients_text,
ingredients_text_with_allergens => $ingredients_text_with_allergens,
ingredients_text_lc => $ingredients_text_lc,
ingredients_text_lc => (
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why you made that change, but it's breaking the actions in knowledge panels:

  •                 "edit_field_id" : "ingredients_text_en",
    
  •                 "edit_field_id" : "ingredients_text_English",
    

I will change it back.

@@ -9054,11 +9055,14 @@ sub data_to_display_nutrient_levels ($product_ref) {

if ((defined $product_ref->{nutrient_levels}) and (defined $product_ref->{nutrient_levels}{$nid})) {

my $nutriment_value = $product_ref->{nutriments}{$nid . $prepared . "_100g"};
my $formatted_value = $nutriment_value
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't really understand this part, but it doesn't work:

-               "title" : "Salt in high quantity (120%)"
+               "title" : "Salt in high quantity (1.20e+02%)"

Copy link

sonarcloud bot commented Jun 4, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarCloud

@stephanegigandet stephanegigandet merged commit 238edaf into main Jun 4, 2024
12 checks passed
@stephanegigandet stephanegigandet deleted the fix_wanings_modperl_error_log branch June 4, 2024 14:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Display 🌱 Eco-Score https://world.openfoodfacts.org/eco-score-the-environmental-impact-of-food-products 📖 Knowledge Panels https://wiki.openfoodfacts.org/Knowledge_panels logs 📍 Origins Origins are used for Eco-Score computation. We want to have structured origins. Products Tags Template::Toolkit The templating toolkit used by product opener. The starting point for HTML/JS/CSS fixes. 🧪 tests
Projects
Development

Successfully merging this pull request may close these issues.

Investigate and fix warnings logged in production in modperl_error_log
2 participants