From 2fe34e87e8845a8afbd1eb374f9e17c89972245e Mon Sep 17 00:00:00 2001 From: arnav Date: Mon, 14 Oct 2024 23:38:21 -0700 Subject: [PATCH] wrapping try-catch around fs.stat on cli arg --- src/lib/getCurrentProjectFile.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/getCurrentProjectFile.ts b/src/lib/getCurrentProjectFile.ts index 27d25c4bb8..d3638cb263 100644 --- a/src/lib/getCurrentProjectFile.ts +++ b/src/lib/getCurrentProjectFile.ts @@ -1,5 +1,6 @@ import * as path from 'path' import * as fs from 'fs/promises' +import { Stats } from 'fs' import { Models } from '@kittycad/lib/dist/types/src' import { PROJECT_ENTRYPOINT } from './constants' @@ -43,8 +44,16 @@ export default async function getCurrentProjectFile( ? sourcePath : path.join(process.cwd(), sourcePath) + let stats: Stats + try { + stats = await fs.stat(sourcePath) + } catch (error) { + return new Error( + `Unable to access the path: ${sourcePath}. Error: ${error}` + ) + } + // If the path is a directory, let's assume it is a project directory. - const stats = await fs.stat(sourcePath) if (stats.isDirectory()) { // Walk the directory and look for a kcl file. const files = await fs.readdir(sourcePath)