From 14cbd0cd3bb101379e8166e6afa12c9331de523c Mon Sep 17 00:00:00 2001 From: ayush-coder-hai Date: Tue, 19 Sep 2023 14:56:09 +0530 Subject: [PATCH 1/3] handle the case if the file is not present. --- src/commands/new/file.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/commands/new/file.ts b/src/commands/new/file.ts index 98159a3f6d4..83c3a5fa043 100644 --- a/src/commands/new/file.ts +++ b/src/commands/new/file.ts @@ -160,11 +160,16 @@ 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') { + console.error('Permission denied to read the file. You do not have the necessary permissions.'); + } else { + await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' }); + console.log(`Created file ${fileNameToWriteToDisk}...`); + + } } - await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' }); - console.log(`Created file ${fileNameToWriteToDisk}...`); } } From 972cef0a351c572ae3ee994a9b584b88417c4fb6 Mon Sep 17 00:00:00 2001 From: ayush-coder-hai Date: Tue, 26 Sep 2023 22:56:15 +0530 Subject: [PATCH 2/3] remove the lint error --- src/commands/new/file.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/commands/new/file.ts b/src/commands/new/file.ts index 83c3a5fa043..fbe83632133 100644 --- a/src/commands/new/file.ts +++ b/src/commands/new/file.ts @@ -160,16 +160,13 @@ export default class NewFile extends Command { console.log(`File ${fileNameToWriteToDisk} already exists. Ignoring...`); return; } - } catch (e:any ) { - + } catch (e:any) { if (e.code === 'EACCES') { console.error('Permission denied to read the file. You do not have the necessary permissions.'); } else { await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' }); console.log(`Created file ${fileNameToWriteToDisk}...`); - } } - } } From 0bb6b5dfcd2ae27e9a8c301bd339ca86ecae27d3 Mon Sep 17 00:00:00 2001 From: ayush-coder-hai Date: Sat, 30 Sep 2023 19:09:17 +0530 Subject: [PATCH 3/3] made the required changes. --- src/commands/new/file.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/commands/new/file.ts b/src/commands/new/file.ts index fbe83632133..37b8edf263f 100644 --- a/src/commands/new/file.ts +++ b/src/commands/new/file.ts @@ -162,11 +162,10 @@ export default class NewFile extends Command { } } catch (e:any) { if (e.code === 'EACCES') { - console.error('Permission denied to read the file. You do not have the necessary permissions.'); - } else { - await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' }); - console.log(`Created file ${fileNameToWriteToDisk}...`); + 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}...`); } }