Skip to content

Commit bc0ccd1

Browse files
committed
feat(vscode): handling python errors well
1 parent 079efc8 commit bc0ccd1

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

sqlmesh/core/config/loader.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,14 @@ def load_config_from_python_module(
184184
module_path: Path,
185185
config_name: str = "config",
186186
) -> C:
187-
with sys_path(module_path.parent):
188-
config_module = import_python_file(module_path, module_path.parent)
187+
try:
188+
with sys_path(module_path.parent):
189+
config_module = import_python_file(module_path, module_path.parent)
190+
except Exception as e:
191+
raise ConfigError(
192+
f"Failed to load config file: {str(e)}",
193+
location=module_path,
194+
)
189195

190196
try:
191197
config_obj = getattr(config_module, config_name)

vscode/extension/tests/broken_project.spec.ts

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -395,9 +395,46 @@ test.describe('Bad config.py/config.yaml file issues', () => {
395395
await runCommand(page, 'View: Focus Problems')
396396

397397
// Assert that the error is present in the problems view
398-
await page
398+
const errorElement = page
399399
.getByText('Config needs to be a valid object of type')
400400
.first()
401-
.isVisible({ timeout: 5_000 })
401+
expect(await errorElement.isVisible({ timeout: 5_000 })).toBe(true)
402+
})
403+
404+
test('sushi example, bad config.py', async ({ page, sharedCodeServer }) => {
405+
const tempDir = await fs.mkdtemp(
406+
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
407+
)
408+
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
409+
await createPythonInterpreterSettingsSpecifier(tempDir)
410+
411+
const configPyPath = path.join(tempDir, 'config.py')
412+
// Write an invalid Python to config.py
413+
await fs.writeFile(configPyPath, 'invalid_python_code = [1, 2, 3')
414+
415+
await page.goto(
416+
`http://127.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
417+
)
418+
await page.waitForLoadState('networkidle')
419+
420+
// Open customers.sql model
421+
await page
422+
.getByRole('treeitem', { name: 'models', exact: true })
423+
.locator('a')
424+
.click()
425+
await page
426+
.getByRole('treeitem', { name: 'customers.sql', exact: true })
427+
.locator('a')
428+
.click()
429+
430+
// Expect the error to appear
431+
await page.waitForSelector('text=Error creating context')
432+
433+
// Open the problems view
434+
await runCommand(page, 'View: Focus Problems')
435+
436+
// Assert that the error is present in the problems view
437+
const errorElement = page.getByText('Failed to load config file:').first()
438+
expect(await errorElement.isVisible({ timeout: 5_000 })).toBe(true)
402439
})
403440
})

0 commit comments

Comments
 (0)