Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions sqlmesh/core/config/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,14 @@ def load_config_from_python_module(
module_path: Path,
config_name: str = "config",
) -> C:
with sys_path(module_path.parent):
config_module = import_python_file(module_path, module_path.parent)
try:
with sys_path(module_path.parent):
config_module = import_python_file(module_path, module_path.parent)
except Exception as e:
Copy link

Copilot AI Jul 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add exception chaining by raising the new ConfigError with from e (e.g., raise ConfigError(...) from e) to preserve the original traceback.

Copilot uses AI. Check for mistakes.
raise ConfigError(
f"Failed to load config file: {e}",
location=module_path,
)

try:
config_obj = getattr(config_module, config_name)
Expand Down
41 changes: 39 additions & 2 deletions vscode/extension/tests/broken_project.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -395,9 +395,46 @@ test.describe('Bad config.py/config.yaml file issues', () => {
await runCommand(page, 'View: Focus Problems')

// Assert that the error is present in the problems view
await page
const errorElement = page
.getByText('Config needs to be a valid object of type')
.first()
.isVisible({ timeout: 5_000 })
await expect(errorElement).toBeVisible({ timeout: 5000 })
})

test('sushi example, bad config.py', async ({ page, sharedCodeServer }) => {
const tempDir = await fs.mkdtemp(
path.join(os.tmpdir(), 'vscode-test-tcloud-'),
)
await fs.copy(SUSHI_SOURCE_PATH, tempDir)
await createPythonInterpreterSettingsSpecifier(tempDir)

const configPyPath = path.join(tempDir, 'config.py')
// Write an invalid Python to config.py
await fs.writeFile(configPyPath, 'invalid_python_code = [1, 2, 3')

await page.goto(
`http://127.0.1:${sharedCodeServer.codeServerPort}/?folder=${tempDir}`,
)
await page.waitForLoadState('networkidle')

// Open customers.sql model
await page
.getByRole('treeitem', { name: 'models', exact: true })
.locator('a')
.click()
await page
.getByRole('treeitem', { name: 'customers.sql', exact: true })
.locator('a')
.click()

// Expect the error to appear
await page.waitForSelector('text=Error creating context')

// Open the problems view
await runCommand(page, 'View: Focus Problems')

// Assert that the error is present in the problems view
const errorElement = page.getByText('Failed to load config file:').first()
await expect(errorElement).toBeVisible({ timeout: 5000 })
})
})