fix(type-mapping): fall back on sqlglot TokenError, not just ParseError#2433
fix(type-mapping): fall back on sqlglot TokenError, not just ParseError#2433Bartok9 wants to merge 1 commit into
Conversation
parse_type/translate_type promise to fall back to the raw string when parsing fails, but only caught (ParseError, ValueError). sqlglot's tokenizer raises TokenError (a SqlglotError, not a ParseError subclass) on unterminated quotes or stray control chars in a type string, so those inputs crashed callers instead of falling back. Catch SqlglotError, which is the common parent of ParseError and TokenError.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughException handling in ChangesType Mapping Fallback Handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
parse_type/translate_typeincore/wren/src/wren/type_mapping.pynow fall back to the raw string on any sqlglot failure, not justParseError.TokenErrorcrash on malformed type strings (unterminated quotes, stray control chars).Motivation
Both functions document: "Falls back to original string if parsing fails." They only caught
(sqlglot.errors.ParseError, ValueError). But sqlglot's tokenizer raisessqlglot.errors.TokenError, which is aSqlglotErrorand not a subclass ofParseError. So a type string like"unterminated(or one containing a stray\x00) escaped the fallback and propagated up, crashing callers (e.g.parse_types/translate_typesover a batch of introspected columns).The fix catches
sqlglot.errors.SqlglotError, the common parent of bothParseErrorandTokenError, matching the documented fallback contract.Verification
Real output on current
upstream/main(fix reverted, tests present):With the fix applied:
parse_type, 1 fortranslate_type) that fail without the fix.core/**).Summary by CodeRabbit