Skip to content

Conversation

@Oxilod
Copy link
Contributor

@Oxilod Oxilod commented May 25, 2025

User description

🔗 Related Issues

Fixes #15790

💥 What does this PR do?

Fixing issue where providing an invalid log level to Grid will fail silently.

🔧 Implementation Notes

Since the logger is not yet configured a stacktrace with the exception is printed to console and we continue since the default log level is already configured.

I've considered percolating the exception up to the TemplateGrid.java, configure() method and doing a try catch there but to me it's unnecessarily complicated.

🔄 Types of changes

  • Bug fix (backwards compatible)

PR Type

Bug fix


Description

  • Print stacktrace when invalid log level is provided

  • Prevent silent failure by notifying via console output

  • Default log level is used if invalid value is given


Changes walkthrough 📝

Relevant files
Bug fix
LoggingOptions.java
Handle invalid log level with stacktrace and fallback       

java/src/org/openqa/selenium/grid/log/LoggingOptions.java

  • Catches invalid log level and prints stacktrace to console
  • Continues with default log level instead of failing silently
  • +3/-1     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Fixing issue where providing an invalid log level to Grid will fail silently. Since the logger is not yet configured a stacktrace with the exception is printed to console and we continue since the default log level is already configured. Fixes SeleniumHQ#15790
    @CLAassistant
    Copy link

    CLAassistant commented May 25, 2025

    CLA assistant check
    All committers have signed the CLA.

    @selenium-ci selenium-ci added B-grid Everything grid and server related C-java Java Bindings labels May 25, 2025
    @qodo-merge-pro
    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Default Value Assignment

    The code catches the exception but doesn't explicitly set the level to the default value when an invalid log level is provided. The level variable might remain uninitialized if the exception occurs.

    } catch (IllegalArgumentException e) { // Logger is not configured yet new ConfigException("Unable to determine log level from " + configLevel + ". Using default " + DEFAULT_LOG_LEVEL).printStackTrace();
    @qodo-merge-pro
    Copy link
    Contributor

    qodo-merge-pro bot commented May 25, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Set default log level

    The code creates a ConfigException but doesn't set the default log level when an
    invalid level is provided. After printing the stack trace, you should explicitly
    set the level to DEFAULT_LOG_LEVEL to ensure consistent behavior.

    java/src/org/openqa/selenium/grid/log/LoggingOptions.java [76-82]

     try { level = Level.parse(configLevel.toUpperCase(Locale.ROOT)); } catch (IllegalArgumentException e) { // Logger is not configured yet new ConfigException("Unable to determine log level from " + configLevel + ". Using default " + DEFAULT_LOG_LEVEL).printStackTrace(); + level = Level.parse(DEFAULT_LOG_LEVEL); }
    • Apply / Chat
    Suggestion importance[1-10]: 8

    __

    Why: This suggestion ensures that when an invalid log level is provided, the code explicitly sets the log level to the default, preventing potential issues with an unset or inconsistent logging state. This is a significant improvement in robustness and error handling.

    Medium
    • Update
    @VietND96 VietND96 requested a review from diemol May 26, 2025 00:47
    @cgoldberg
    Copy link
    Member

    @Oxilod Can you run the formatter against your branch to fix the CI failure?

    ./scripts/format.sh

    Oxilod added 2 commits May 26, 2025 12:33
    Adding link to logging levels as suggested by @diemol and formatting.
    @Oxilod
    Copy link
    Contributor Author

    Oxilod commented May 26, 2025

    @cgoldberg Sorry for the formatting issue. I've fixed it by running the script and pushed the changes.

    Adding hardcoded log levels as suggested by review.
    @diemol
    Copy link
    Member

    diemol commented May 26, 2025

    Thank you, @Oxilod!

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    B-grid Everything grid and server related C-java Java Bindings Review effort 1/5

    6 participants