-
-
Notifications
You must be signed in to change notification settings - Fork 172
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
perf: handle the case if the file is not present. #812
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Welcome to AsyncAPI. Thanks a lot for creating your first pull request. Please check out our contributors guide useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ayush2020012016 tests are failing due to lint issues. To fix lint issues just run
npm run lint:fix
@Ayush2020012016 @Souvikns If we follow that logic then we should leave the creation of the file outside the WDYT? Any thoughts on this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here my suggestion :)
src/commands/new/file.ts
Outdated
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' }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave the "creation of the file" outside the catch
, so it's not be treated as an error like I explain here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok @peter-rr will do that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peter-rr should i create file even though there is the permission error? means even though we dont have permission to read the file we just created it. it will look like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
till then i have ran the lint command please consider merging it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peter-rr should i create file even though there is the permission error? means even though we dont have permission to read the file we just created it. it will look like this.
Nope, we should not create the file if a permission error occurs. In that case we should throw the error so that we exit the execution and the file is not created then:
} catch (e) {
if (e.code === 'EACCES') {
throw e;
}
}
await writeFile(fileNameToWriteToDisk, asyncApiFile, { encoding: 'utf8' });
console.log(`Created file ${fileNameToWriteToDisk}...`);
Another alternative we have is using this.error
instead, since OCLIF makes use of it as console.error
+ throw e
:
} catch (e) {
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}...`);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok will do that. @peter-rr
I think you are doing it right and getting the expected behaviour: if the user does not have the necessary permissions to read the file, then the error is thrown, the flow execution stops and a new file is not created. Otherwise the already existing file could be overwritten by a new file with the same name. Am I answering your question? @ayushnau |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
/rtm |
🎉 This PR is included in version 0.58.8 🎉 The release is available on: Your semantic-release bot 📦🚀 |
@allcontributors please add @ayushnau for code |
I've put up a pull request to add @ayushnau! 🎉 |
I have worked on the issue no. #800 .