Skip to content

Commit d911d99

Browse files
authored
feat(vscode): adding validation to config (#5126)
1 parent 13ae8e3 commit d911d99

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

vscode/extension/src/utilities/config.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ import { traceVerbose, traceInfo } from './common/log'
66
import { parse } from 'shell-quote'
77
import { z } from 'zod'
88

9-
export interface SqlmeshConfiguration {
10-
projectPath: string
11-
lspEntryPoint: string
12-
}
9+
const configSchema = z.object({
10+
projectPath: z.string(),
11+
lspEntryPoint: z.string(),
12+
})
13+
14+
export type SqlmeshConfiguration = z.infer<typeof configSchema>
1315

1416
/**
1517
* Get the SQLMesh configuration from VS Code settings.
@@ -20,10 +22,17 @@ function getSqlmeshConfiguration(): SqlmeshConfiguration {
2022
const config = workspace.getConfiguration('sqlmesh')
2123
const projectPath = config.get<string>('projectPath', '')
2224
const lspEntryPoint = config.get<string>('lspEntrypoint', '')
23-
return {
25+
26+
const parsed = configSchema.safeParse({
2427
projectPath,
2528
lspEntryPoint,
29+
})
30+
if (!parsed.success) {
31+
throw new Error(
32+
`Invalid sqlmesh configuration: ${JSON.stringify(parsed.error)}`,
33+
)
2634
}
35+
return parsed.data
2736
}
2837

2938
const stringsArray = z.array(z.string())

0 commit comments

Comments
 (0)