Skip to content

Commit 0d6193d

Browse files
authored
feat(vscode): error well on bad config.yaml (#4946)
1 parent 8421488 commit 0d6193d

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

sqlmesh/core/config/loader.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,14 @@ def load_config_from_paths(
169169

170170

171171
def load_config_from_yaml(path: Path) -> t.Dict[str, t.Any]:
172-
return yaml_load(path)
172+
content = yaml_load(path)
173+
if not isinstance(content, dict):
174+
raise ConfigError(
175+
f"Invalid YAML configuration: expected a dictionary but got {type(content).__name__}. "
176+
f"Please check the YAML syntax in your config file.",
177+
location=path,
178+
)
179+
return content
173180

174181

175182
def load_config_from_python_module(

vscode/extension/tests/broken_project.spec.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,48 @@ const setup = async (tempDir: string) => {
271271
}
272272

273273
test.describe('Bad config.py/config.yaml file issues', () => {
274+
test('sqlmesh init, then corrupted config.yaml, bad yaml', async ({
275+
page,
276+
sharedCodeServer,
277+
}) => {
278+
const tempDir = await fs.mkdtemp(
279+
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
280+
)
281+
await setup(tempDir)
282+
await createPythonInterpreterSettingsSpecifier(tempDir)
283+
284+
const configYamlPath = path.join(tempDir, 'config.yaml')
285+
// Write an invalid YAML to config.yaml
286+
await fs.writeFile(configYamlPath, 'invalid_yaml; asdfasudfy')
287+
288+
await page.goto(
289+
`http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
290+
)
291+
await page.waitForLoadState('networkidle')
292+
293+
// Open full_model.sql model
294+
await page
295+
.getByRole('treeitem', { name: 'models', exact: true })
296+
.locator('a')
297+
.click()
298+
await page
299+
.getByRole('treeitem', { name: 'full_model.sql', exact: true })
300+
.locator('a')
301+
.click()
302+
303+
// Wait for the error to appear
304+
await page.waitForSelector('text=Error creating context')
305+
306+
// Open the problems view
307+
await runCommand(page, 'View: Focus Problems')
308+
309+
// Asser that the error is present in the problems view
310+
await page
311+
.getByText('Invalid YAML configuration:')
312+
.first()
313+
.isVisible({ timeout: 5_000 })
314+
})
315+
274316
test('sqlmesh init, then corrupted config.yaml, bad parameters', async ({
275317
page,
276318
sharedCodeServer,

0 commit comments

Comments
 (0)