diff --git a/sqlmesh/core/config/loader.py b/sqlmesh/core/config/loader.py index 1618d29ad2..5485b0f623 100644 --- a/sqlmesh/core/config/loader.py +++ b/sqlmesh/core/config/loader.py @@ -169,7 +169,14 @@ def load_config_from_paths( def load_config_from_yaml(path: Path) -> t.Dict[str, t.Any]: - return yaml_load(path) + content = yaml_load(path) + if not isinstance(content, dict): + raise ConfigError( + f"Invalid YAML configuration: expected a dictionary but got {type(content).__name__}. " + f"Please check the YAML syntax in your config file.", + location=path, + ) + return content def load_config_from_python_module( diff --git a/vscode/extension/tests/broken_project.spec.ts b/vscode/extension/tests/broken_project.spec.ts index 744197e3bb..605a622787 100644 --- a/vscode/extension/tests/broken_project.spec.ts +++ b/vscode/extension/tests/broken_project.spec.ts @@ -271,6 +271,48 @@ const setup = async (tempDir: string) => { } test.describe('Bad config.py/config.yaml file issues', () => { + test('sqlmesh init, then corrupted config.yaml, bad yaml', async ({ + page, + sharedCodeServer, + }) => { + const tempDir = await fs.mkdtemp( + path.join(os.tmpdir(), 'vscode-test-tcloud-'), + ) + await setup(tempDir) + await createPythonInterpreterSettingsSpecifier(tempDir) + + const configYamlPath = path.join(tempDir, 'config.yaml') + // Write an invalid YAML to config.yaml + await fs.writeFile(configYamlPath, 'invalid_yaml; asdfasudfy') + + await page.goto( + `http://127.0.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`, + ) + await page.waitForLoadState('networkidle') + + // Open full_model.sql model + await page + .getByRole('treeitem', { name: 'models', exact: true }) + .locator('a') + .click() + await page + .getByRole('treeitem', { name: 'full_model.sql', exact: true }) + .locator('a') + .click() + + // Wait for the error to appear + await page.waitForSelector('text=Error creating context') + + // Open the problems view + await runCommand(page, 'View: Focus Problems') + + // Asser that the error is present in the problems view + await page + .getByText('Invalid YAML configuration:') + .first() + .isVisible({ timeout: 5_000 }) + }) + test('sqlmesh init, then corrupted config.yaml, bad parameters', async ({ page, sharedCodeServer,