Fix: ignore blank lines in parser (Resolves #32)#33
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughOverviewThis PR fixes a parser issue where leading blank lines in ChangesBallerina Interpreter
Python Interpreter
Impact
WalkthroughThis pull request fixes a bug in both Ballerina and Python AFM parsers where frontmatter was ignored if the document began with blank lines. The Ballerina implementation preprocesses the resolved content by stripping leading blank lines before computing line splits and detecting the opening 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
Purpose
When an
.afm.mdfile has one or more blank lines before the opening---, both interpreters ignore the whole frontmatter. Because of this, themodelblock is dropped and the interpreter silently falls back to its default provider (OpenAI in Python, WSO2 in Ballerina), which then fails with a confusing, unrelated error (e.g. "No API key found"). The provider the user actually wrote is never used.Resolves #32
Goals
ollama) actually uses that provider, even if it starts with a blank line.Approach
packages/afm-core/src/afm/parser.py): inextract_raw_frontmatter, skip leading blank lines before checking for the opening---. This function is shared by the AFM parser and the skills parser, so both are fixed.ballerina-interpreter/parser.bal): inparseAfm, drop leading blank lines from the content before detecting the frontmatter.Both changes are a no-op for normal files (where
---is already the first line), so existing behaviour is unchanged. A regression test was added in each interpreter that parses a file starting with blank lines and confirms themodelblock is read correctly.No UI changes.
User stories
---, the interpreter still reads my frontmatter and uses the model/provider I declared, instead of silently using a default one.Release note
Fixed AFM files that begin with blank lines before the
---frontmatter being parsed as having no frontmatter, which caused the declared model provider to be ignored. Leading blank lines are now skipped in both the Python and Ballerina interpreters.