Skip to content

Conversation

@BugelNiels
Copy link
Contributor

Updates the enum_to_string function to have a more elaborate error messages. I had to move around the get_enumerators() and related functions as one of them was needed to implement this fix (get_enumerator_array). I figured this was cleaner than forward declaring it in the same file.

I have also added a few basic tests to verify the error behaviour. Let me know if additional tests are needed here.

Fixes #605

@gemini-code-assist
Copy link

Summary of Changes

Hello @BugelNiels, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the diagnostic feedback for users attempting to convert invalid strings to enum types. By generating a comprehensive error message that includes the expected enum values, it makes debugging and understanding conversion failures much easier. The changes also involve a minor refactoring of internal enum utility functions to facilitate this enhancement, along with the addition of robust test cases.

Highlights

  • Improved Enum Error Messages: The string_to_enum function now provides more descriptive error messages when an invalid enum value is encountered, listing all valid enumerator options.
  • Refactoring of Enum Helper Functions: Several get_ helper functions within include/rfl/enums.hpp were reordered to ensure get_enumerator_array is available for use in the improved error message generation.
  • New Error Message Tests: Dedicated tests have been added to tests/json/test_enum_error_messages.cpp to validate the behavior and content of the new error messages for various invalid enum inputs.
Changelog
  • include/rfl/enums.hpp
    • Relocated get_enumerators, get_underlying_enumerators, get_enumerator_array, get_underlying_enumerator_array, and get_enum_range functions to an earlier position in the file.
    • Enhanced the error message generated by string_to_enum for invalid inputs to include the provided invalid value and a list of all valid enum options.
  • tests/json/test_enum_error_messages.cpp
    • Added a new test file to specifically test the improved error messages for string_to_enum.
    • Included tests for invalid, empty, and case-sensitive string inputs to ensure correct error reporting.
Activity
  • Author BugelNiels initiated the pull request to improve error messages for invalid enum conversions.
  • The author refactored the placement of get_enumerators() and related functions to enable the fix.
  • Basic tests were added to verify the error behavior, with the author inviting feedback on the need for additional tests.
  • This PR addresses and fixes issue Improve error message when an invalid enum value is provided. #605.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request improves the error message for invalid enum string conversions by listing the available enum values. The change is well-implemented and includes new tests to verify the behavior. I've made a few suggestions to improve code clarity and fix a minor typo in the tests.

@BugelNiels BugelNiels force-pushed the improve-enum-error-messages branch from ebfeb30 to c06105f Compare February 9, 2026 21:21
@BugelNiels BugelNiels force-pushed the improve-enum-error-messages branch from c06105f to 2fc0cb1 Compare February 10, 2026 07:33
@BugelNiels
Copy link
Contributor Author

Replaced the std::ostringstream with regular strings so that it doesn't need an additional import. The currently failing tests all seem to be due to transient download failures.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when an invalid enum value is provided.

1 participant