|
| 1 | +--- |
| 2 | +# Valid statuses: draft | proposed | rejected | accepted | superseded |
| 3 | +status: draft |
| 4 | +author: Simon Schrottner |
| 5 | +created: 2025-07-17 |
| 6 | +updated: YYYY-MM-DD |
| 7 | +--- |
| 8 | + |
| 9 | +# Proposal for Unified Flag Parsing and Handling |
| 10 | + |
| 11 | +The goal of this proposal is to standardize how flags are parsed and handled across implementations. Currently, there is significant variation in how this is done, stemming from the organic growth of the project and contributions from multiple developers. This proposal aims to rethink and unify the parsing and handling of configurations, particularly for in-process scenarios. |
| 12 | + |
| 13 | +## Background |
| 14 | + |
| 15 | +Over time, the project has grown with contributions from various developers, leading to inconsistencies in how flags are parsed and handled. These inconsistencies have resulted in bugs, unexpected behaviors, and challenges in maintaining the codebase. For example, the file provider and JSON parsing behave differently across languages, and there is no clear definition of what constitutes a parsing error versus a flag-not-found error. |
| 16 | + |
| 17 | +Several issues have been raised that highlight the need for a unified approach: |
| 18 | + |
| 19 | +- [BUG] Inconsistency in file provider and JSON parsing for different languages (#1627) |
| 20 | +- [BUG] [File Provider] Support File Formats (#1689) |
| 21 | +- [FEATURE] Provider option to reject flag set with invalid rules (#1487) |
| 22 | + |
| 23 | +To address these issues, it is essential to establish a consistent and testable framework for flag parsing and handling. |
| 24 | + |
| 25 | +## Requirements |
| 26 | + |
| 27 | +* Utilize schema validation as much as possible, instead of custom logic, on a flag level rather than a configuration level. |
| 28 | +* Define what consistutes a `PARSE_ERROR` versus a `FLAG_NOT_FOUND`. |
| 29 | +* Define if an invalid flag entry within a configuration can invalidate the whole configuration. |
| 30 | +* Define which file formats are supported (e.g., JSON, YAML, etc.). |
| 31 | +* Ensure the framework is testable via the existing testbed/test-harness. |
| 32 | + |
| 33 | +## Considered Options |
| 34 | + |
| 35 | +* Standardize flag parsing and handling using schema validation (Option 1). |
| 36 | +* Continue with the current approach but document the inconsistencies (Option 2). |
| 37 | +* Develop separate parsing logic for each implementation to address specific needs (Option 3). |
| 38 | + |
| 39 | +## Proposal |
| 40 | + |
| 41 | +### Standardize Flag Parsing and Handling Using Schema Validation (Option 1) |
| 42 | + |
| 43 | +This proposal recommends adopting schema validation as the primary method for parsing and handling flags. The key elements of this approach include: |
| 44 | + |
| 45 | +1. **Schema Validation**: Use schema validation to ensure that flags meet predefined criteria. This reduces the reliance on custom logic and improves consistency across implementations. |
| 46 | +2. **Supported File Formats**: Define and document the file formats that are supported (e.g., JSON, YAML). This aligns with the issue raised in [BUG] [File Provider] Support File Formats (#1689). |
| 47 | +3. **Error Definitions**: Clearly define what constitutes a `PARSE_ERROR` versus a `FLAG_NOT_FOUND` error. Each inconsistent flag should evaluate as a `PARSE_ERROR`, only if the flag is not part of the configuration (or due to other definitions), it should evaluate to a `FLAG_NOT_FOUND` |
| 48 | +4. **Invalid Flag Handling**: A invalid flag configuration should not affect the whole configuration. Other valid flags might still be important, and an error on one flag should not hinder updates or changes to the flag configuration. |
| 49 | +4. **Testability**: Design the framework to be testable using the existing testbed/test-harness. This ensures that the implementation is robust and meets the defined requirements. |
| 50 | + |
| 51 | +### API Changes |
| 52 | + |
| 53 | +No immediate API changes are proposed. However, the internal logic for flag parsing and handling will be standardized, which may indirectly impact APIs that rely on these processes. |
| 54 | + |
| 55 | +### Consequences |
| 56 | + |
| 57 | +* **Positive Consequences**: |
| 58 | + * Improved consistency across implementations. |
| 59 | + * Easier maintenance and debugging. |
| 60 | + * Enhanced testability and reliability. |
| 61 | +* **Negative Consequences**: |
| 62 | + * Initial development effort to implement the unified framework. |
| 63 | + * Potential learning curve for contributors to adapt to the new framework. |
| 64 | + |
| 65 | +### Timeline |
| 66 | + |
| 67 | + |
| 68 | +### Open Questions |
| 69 | + |
| 70 | +* Are there any edge cases that need to be addressed in the schema validation rules? |
| 71 | + |
| 72 | +## More Information |
| 73 | + |
| 74 | +For additional context, refer to the following issues: |
| 75 | + |
| 76 | +- [BUG] Inconsistency in file provider and JSON parsing for different languages (#1627) |
| 77 | +- [BUG] [File Provider] Support File Formats (#1689) |
| 78 | +- [FEATURE] Provider option to reject flag set with invalid rules (#1487) |
0 commit comments