@@ -287,6 +287,12 @@ export const sqlmeshExec = async (): Promise<
287287 args : [ ] ,
288288 } )
289289 } else {
290+ const exists = await doesExecutableExist ( sqlmesh )
291+ if ( ! exists ) {
292+ return err ( {
293+ type : 'sqlmesh_not_found' ,
294+ } )
295+ }
290296 return ok ( {
291297 bin : sqlmesh ,
292298 workspacePath,
@@ -384,22 +390,28 @@ export const sqlmeshLspExec = async (): Promise<
384390 type : 'not_signed_in' ,
385391 } )
386392 }
393+ const exists = await doesExecutableExist ( sqlmeshLSP )
394+ if ( ! exists ) {
395+ return err ( {
396+ type : 'sqlmesh_lsp_not_found' ,
397+ } )
398+ }
387399 const ensured = await ensureSqlmeshEnterpriseInstalled ( )
388400 if ( isErr ( ensured ) ) {
389401 return ensured
390402 }
391403 }
392- const ensuredDependencies = await ensureSqlmeshLspDependenciesInstalled ( )
393- if ( isErr ( ensuredDependencies ) ) {
394- return ensuredDependencies
395- }
396404 const binPath = path . join ( interpreterDetails . binPath ! , sqlmeshLSP )
397405 traceLog ( `Bin path: ${ binPath } ` )
398406 if ( ! fs . existsSync ( binPath ) ) {
399407 return err ( {
400408 type : 'sqlmesh_lsp_not_found' ,
401409 } )
402410 }
411+ const ensuredDependencies = await ensureSqlmeshLspDependenciesInstalled ( )
412+ if ( isErr ( ensuredDependencies ) ) {
413+ return ensuredDependencies
414+ }
403415 return ok ( {
404416 bin : binPath ,
405417 workspacePath,
@@ -411,6 +423,12 @@ export const sqlmeshLspExec = async (): Promise<
411423 args : [ ] ,
412424 } )
413425 } else {
426+ const exists = await doesExecutableExist ( sqlmeshLSP )
427+ if ( ! exists ) {
428+ return err ( {
429+ type : 'sqlmesh_lsp_not_found' ,
430+ } )
431+ }
414432 return ok ( {
415433 bin : sqlmeshLSP ,
416434 workspacePath,
@@ -419,3 +437,18 @@ export const sqlmeshLspExec = async (): Promise<
419437 } )
420438 }
421439}
440+
441+ async function doesExecutableExist ( executable : string ) : Promise < boolean > {
442+ const command = process . platform === 'win32' ? 'where.exe' : 'which'
443+ traceLog ( `Checking if ${ executable } exists with ${ command } ` )
444+ try {
445+ const result = await execAsync ( command , [ executable ] )
446+ traceLog ( `Checked if ${ executable } exists with ${ command } , with result ${ result . exitCode } ` )
447+ const exists = result . exitCode === 0
448+ traceLog ( `Checked if ${ executable } exists with ${ command } , with result ${ exists } ` )
449+ return exists
450+ } catch {
451+ traceLog ( `Checked if ${ executable } exists with ${ command } , errored, returning false` )
452+ return false
453+ }
454+ }
0 commit comments