Add dialect config validation with error handling#2428
Add dialect config validation with error handling#2428
Conversation
Dialect config validation now errors when a known config option has a non-boolean value (e.g. pg_trgm = "not_a_bool") and logs a warning for unrecognized config keys. The DialectConfig::from_value trait method and kind_to_dialect now return Result<_, String> to propagate validation errors. https://claude.ai/code/session_01W8Ldw75CKMAj6dcjM6K3NV
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2f3beebc92
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| let dialect = kind_to_dialect(&dialect_kind, dialect_config) | ||
| .expect("Failed to load dialect configuration"); |
There was a problem hiding this comment.
Handle dialect config errors without panicking
When a dialect option has an invalid type, kind_to_dialect() now returns Err, but FluffConfig::new() immediately calls .expect(...) here, which turns user config mistakes into a process panic. This affects normal entry points like from_file(), from_source(), and from_root(), so a malformed [sqruff:dialect:*] value can crash the CLI/library instead of surfacing a recoverable configuration error.
Useful? React with 👍 / 👎.
Benchmark for 3331b5cClick to view benchmark
|
Summary
This PR adds comprehensive validation and error handling for dialect configuration options. Dialect initialization functions now return
Result<Dialect, String>instead ofOption<Dialect>, enabling proper error reporting when configuration values are invalid.Key Changes
DialectConfig::from_value()to returnResult<Self, String>instead ofSelf, allowing validation errors to be propagateddialect(config: Option<&Value>) -> Dialectsignatures todialect(config: Option<&Value>) -> Result<Dialect, String>across all 13 dialect implementationskind_to_dialect(): Changed return type fromOption<Dialect>toResult<Dialect, String>with descriptive error messages for disabled dialectsImplementation Details
dialect_config!macro now generates validation logic that:.transpose()?pattern for proper error propagationResultreturn typelogworkspace dependency for warning messageshttps://claude.ai/code/session_01W8Ldw75CKMAj6dcjM6K3NV