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: tests if variable defined before use #6724

Merged
merged 1 commit into from
May 10, 2022

Conversation

dipietroR
Copy link
Contributor

On the main page I was seeing the following warning:

[Sun May  1 16:45:15 2022] -e: Use of uninitialized value $current_link_query in concatenation (.) or string at /opt/product-opener/lib/ProductOpener/Display.pm line 5411.

And on the search page I was seeing:

[Sun May  1 16:54:12 2022] -e: Use of uninitialized value $current_link in concatenation (.) or string at /opt/product-opener/lib/ProductOpener/Display.pm line 5411.

This seems to be because they weren't being tested for definition, which was happening later on in the code.

@dipietroR dipietroR requested a review from a team as a code owner May 1, 2022 17:34
Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

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

That would work, but we won't log the info that $current_link is undefined.

There's a way to log multiple variables in a structured way. Here is an example from elsewhere in the code:

$log->info("displaying text from file", { cc => $cc, lc => $lc, lang => $lang, textid => $textid, textlang => $text_lang, file => $file }) if $log->is_info();

So instead of having $current_link and $current_link_query inside the debug text, we can pass them in the 2nd parameter.

Could you use that instead? Thank you!

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 4, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

Copy link
Contributor

@stephanegigandet stephanegigandet left a comment

Choose a reason for hiding this comment

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

Thank you very much @dipietroR !

@stephanegigandet stephanegigandet merged commit a112921 into openfoodfacts:main May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

3 participants