grid/TomlConfig: migrate TOML library to tomlj/tomlj
User description
Thanks for contributing to Selenium! A PR well described will help maintainers to quickly review and merge it
Before submitting your PR, please check our contributing guidelines. Avoid large PRs, help reviewers by making them as simple and short as possible.
Description
This PR uses a new TOML parser as stated in https://github.com/SeleniumHQ/selenium/issues/13538
Motivation and Context
As this TOML library is more maintained than the one used so lesser chances of problems and vulnerabilities.
Types of changes
- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [x] Breaking change (fix or feature that would cause existing functionality to change)
Checklist
- [x] I have read the contributing document.
- [ ] My change requires a change to the documentation.
- [ ] I have updated the documentation accordingly.
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests passed.
PR Type
enhancement, dependencies, tests
Description
- Migrated the TOML parsing library from
jtomltotomljin theTomlConfigclass to ensure better maintenance and reduce vulnerabilities. - Implemented error handling for TOML parsing errors using the
tomljlibrary. - Updated tests to validate the new error handling and ensure compatibility with the
tomljlibrary. - Adjusted Bazel and Maven configurations to replace
jtomlwithtomlj.
Changes walkthrough 📝
| Relevant files | |||||||||
|---|---|---|---|---|---|---|---|---|---|
| Enhancement |
| ||||||||
| Tests |
| ||||||||
| Dependencies |
|
💡 PR-Agent usage: Comment
/helpon the PR to get a list of all available PR-Agent tools and their descriptions
As this TOML library uses a different approach compared to the old one. I would require help from the core maintainers to pass the tests and may have to change the tests and add more accordingly.
PR Reviewer Guide 🔍
| ⏱️ Estimated effort to review: 3 🔵🔵🔵⚪⚪ |
| 🧪 PR contains tests |
| 🔒 No security concerns identified |
| ⚡ Key issues to review Error Handling Possible Performance Issue |
PR Code Suggestions ✨
| Category | Suggestion | Score |
| Best practice |
Use try-with-resources to automatically close the readerConsider using a try-with-resources statement to ensure that the reader is properly java/src/org/openqa/selenium/grid/config/TomlConfig.java [42-44]
Suggestion importance[1-10]: 8Why: Using try-with-resources is a best practice for managing resources like readers, ensuring they are closed properly, which can prevent resource leaks. | 8 |
Use a null-safe method for converting values to stringsConsider using a null-safe method like java/src/org/openqa/selenium/grid/config/TomlConfig.java [125]
Suggestion importance[1-10]: 6Why: Using Objects.toString() is a null-safe way to convert objects to strings, which can prevent potential NullPointerExceptions. | 6 | |
| Enhancement |
Use a more specific exception type for TOML parsing errorsConsider using a more specific exception type for TOML parsing errors instead of the java/src/org/openqa/selenium/grid/config/TomlConfig.java [46-51]
Suggestion importance[1-10]: 7Why: Using a more specific exception type like TomlParseException can improve error handling by providing more detailed information about the nature of the error. | 7 |
Add more specific assertions for error handling testsConsider adding more specific assertions to check the exact error message or java/test/org/openqa/selenium/grid/config/TomlConfigTest.java [42-43]
Suggestion importance[1-10]: 7Why: Adding specific assertions for error messages can improve test robustness by ensuring that the correct exceptions are thrown with expected messages. | 7 |
Updating the TOML parser will lead to a breaking change for users.
Example: With the current TOML parser:
// This throws errors with the new parser tomlj
String raw = "[cheeses]\nselected=brie";
Config config = new TomlConfig(new StringReader(raw))
After the new TOML parser:
String raw = "[cheeses]\nselected=\"brie\"";
Config config = new TomlConfig(new StringReader(raw));
The new parser requires quotes for the string values. Since our maven Grid package provides access to creating TomlConfig objects, it will be a breaking change for users.
We can add a warning with the current code base about the upcoming change, and maybe merge this PR after 2 versions so the end users get a chance to update the TOML.
@diemol What do you think?
@pujagani I believe we should go with giving a warning for this as it is a breaking change. As said let's merge and introduce this change after next 2 versions 🚀
@Delta456 Would like to create a separate PR displaying the warning?
@Delta456 Would like to create a separate PR displaying the warning?
Sure
https://github.com/SeleniumHQ/selenium/pull/14491 has been merged. Thanks @pujagani!
Please resolve the conflicts when time permits. Thank you!
@Delta456 Please help resolve the merge conflicts when time permits. Thank you!
@Delta456 Please help resolve the merge conflicts when time permits. Thank you!
I can only fix the merge conflicts when the #14711 PR is merged
@pujagani should be done now.