@@ -13,21 +13,49 @@ export type ErrorType =
1313 // tcloud_bin_not_found is used when the tcloud executable is not found. This is likely to happen if the user
1414 // opens a project that has a `tcloud.yaml` file but doesn't have tcloud installed.
1515 | { type : 'tcloud_bin_not_found' }
16- // sqlmesh_lsp_dependencies_missing is used when the sqlmesh_lsp is found but the lsp extras are missing.
1716 | SqlmeshLspDependenciesMissingError
1817
18+ /**
19+ * SqlmeshLspDependenciesMissingError is used when the sqlmesh_lsp is found but
20+ * the lsp extras are missing.
21+ */
1922interface SqlmeshLspDependenciesMissingError {
2023 type : 'sqlmesh_lsp_dependencies_missing'
2124 is_missing_pygls : boolean
2225 is_missing_lsprotocol : boolean
2326 is_tobiko_cloud : boolean
2427}
2528
29+ export async function handleError (
30+ authProvider : AuthenticationProviderTobikoCloud ,
31+ error : ErrorType ,
32+ genericErrorPrefix ?: string ,
33+ ) : Promise < void > {
34+ traceInfo ( 'handleError' , error )
35+ switch ( error . type ) {
36+ case 'not_signed_in' :
37+ return handleNotSignedInError ( authProvider )
38+ case 'sqlmesh_lsp_not_found' :
39+ return handleSqlmeshLspNotFoundError ( )
40+ case 'sqlmesh_lsp_dependencies_missing' :
41+ return handleSqlmeshLspDependenciesMissingError ( error )
42+ case 'tcloud_bin_not_found' :
43+ return handleTcloudBinNotFoundError ( )
44+ case 'generic' :
45+ if ( genericErrorPrefix ) {
46+ await window . showErrorMessage ( `${ genericErrorPrefix } : ${ error . message } ` )
47+ } else {
48+ await window . showErrorMessage ( `An error occurred: ${ error . message } ` )
49+ }
50+ return
51+ }
52+ }
53+
2654/**
2755 * Handles the case where the user is not signed in to Tobiko Cloud.
2856 * @param authProvider - The authentication provider to use for signing in.
2957 */
30- export const handleNotSginedInError = async (
58+ const handleNotSignedInError = async (
3159 authProvider : AuthenticationProviderTobikoCloud ,
3260) : Promise < void > => {
3361 traceInfo ( 'handleNotSginedInError' )
@@ -43,7 +71,7 @@ export const handleNotSginedInError = async (
4371/**
4472 * Handles the case where the sqlmesh_lsp is not found.
4573 */
46- export const handleSqlmeshLspNotFoundError = async ( ) : Promise < void > => {
74+ const handleSqlmeshLspNotFoundError = async ( ) : Promise < void > => {
4775 traceInfo ( 'handleSqlmeshLspNotFoundError' )
4876 await window . showErrorMessage (
4977 'SQLMesh LSP not found, please check installation' ,
@@ -53,7 +81,7 @@ export const handleSqlmeshLspNotFoundError = async (): Promise<void> => {
5381/**
5482 * Handles the case where the sqlmesh_lsp is found but the lsp extras are missing.
5583 */
56- export const handleSqlmeshLspDependenciesMissingError = async (
84+ const handleSqlmeshLspDependenciesMissingError = async (
5785 error : SqlmeshLspDependenciesMissingError ,
5886) : Promise < void > => {
5987 traceInfo ( 'handleSqlmeshLspDependenciesMissingError' )
@@ -80,7 +108,7 @@ export const handleSqlmeshLspDependenciesMissingError = async (
80108/**
81109 * Handles the case where the tcloud executable is not found.
82110 */
83- export const handleTcloudBinNotFoundError = async ( ) : Promise < void > => {
111+ const handleTcloudBinNotFoundError = async ( ) : Promise < void > => {
84112 const result = await window . showErrorMessage (
85113 'tcloud executable not found, please check installation' ,
86114 'Install' ,
0 commit comments