From ba9df40fe51e08a80ba7c01b27b8958ffb485f4b Mon Sep 17 00:00:00 2001 From: Ayush Nautiyal <78146753+ayushnau@users.noreply.github.com> Date: Mon, 9 Oct 2023 17:11:06 +0530 Subject: [PATCH] perf: handle the case if the file is not present. (#812) Co-authored-by: ayush-coder-hai %0ACo-authored-by: souvik --- src/commands/new/file.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/commands/new/file.ts b/src/commands/new/file.ts index 98159a3f6d4..37b8edf263f 100644 --- a/src/commands/new/file.ts +++ b/src/commands/new/file.ts @@ -160,10 +160,11 @@ export default class NewFile extends Command { console.log(`File ${fileNameToWriteToDisk} already exists. Ignoring...`); return; } - } catch (e) { - // File does not exist. Proceed creating it... + } catch (e:any) { + if (e.code === 'EACCES') { + this.error('Permission denied to read the file. You do not have the necessary permissions.'); + } } - await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' }); console.log(`Created file ${fileNameToWriteToDisk}...`); }