improve(config): add early validation with contextual error messages for ModeSystemConfig#2408
Open
MuhamadRifansyah wants to merge 2 commits intoOpenMind:mainfrom
Open
Conversation
…for ModeSystemConfig
…collection without optional dependencies
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR addresses a medium-risk finding from the codebase review: Late Validation of Required Configuration Fields. Currently, when configuration files are missing required fields, users receive confusing
KeyErrorexceptions instead of structured, actionable error messages that indicate which field is missing and in what context (e.g., which mode, which transition rule).The improvements replace direct dictionary access with validated field retrieval, providing clear context about what went wrong and how to fix it. This makes configuration errors transparent and debuggable without requiring stack trace analysis.
Changes
New Validation Helper Function
_validate_required_field()config.pyValueErrorwith clear remediation instructionsConfiguration Field Validation
Default Mode config.py
raw_config["default_mode"]to early validation with context"Required field 'default_mode' is missing in global configuration..."Mode System Prompt Base config.py
mode_data["system_prompt_base"]to validated retrieval"...in mode 'advanced'"Transition Rule Fields config.py
from_mode,to_mode,transition_typebefore use"...in transition rule at index 2"Cross-Field Validation
Default Mode Existence config.py
default_modereferences an actual defined modeTransition Rule Mode References config.py
from_modeandto_modewith clear contextComprehensive Test Coverage
New Test Class:
TestValidateRequiredFieldtests/runtime/test_config.pyExpanded
TestLoadModeConfigtests/runtime/test_config.pydefault_mode, missingsystem_prompt_base, validation mismatchesImpact
User Experience
Before:
After:
Developer Experience
KeyErrorexceptions far from the root causeReliability
Testing
Quality Assurance Results
Test Execution
All new tests verify:
Additional Information
Scope
Design Decisions
_validate_required_field()for maintainability and consistencyFuture Improvements