-
Notifications
You must be signed in to change notification settings - Fork 293
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
fix: Mitigating undefined bug in alreadyOpenedProject.fsPath
#310
fix: Mitigating undefined bug in alreadyOpenedProject.fsPath
#310
Conversation
alreadyOpenedProject.fsPath
alreadyOpenedProject.fsPath
@@ -31,7 +31,7 @@ export function useLoadProjectWithFileBrowser() { | |||
(p) => p.project.metadata.id === project.metadata.id, | |||
); | |||
|
|||
if (alreadyOpenedProject) { | |||
if (alreadyOpenedProject && alreadyOpenedProject.fsPath) { |
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 think alreadyOpenedPath.fsPath
can be undefined, if the project is a new project that hasn't yet been saved.
Perhaps we can move the check into the toast.error
call instead?
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.
If the project hasn't been saved then a user wouldn't be able to use useLoadProjectWithFileBrowser
would they? Then it seems fine to have the check here. Not sure if I'm interpreting this right
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.
I think my specific suggestion was:
if (alreadyOpenedProject) {
const fileName = alreadyOpenedProject.fsPath?.split('/').pop() ?? '';
toast.error(`"${alreadyOpenedProject.project.metadata.title} [${fileName}]" shares the same ID (...`);
return;
}
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 guess I'm not sure how we get into this situation in the first place ever, so I'm inclined to suggest programming super defensively.
If alreadyOpenedProject
has the same ID as the project we are about to open, we will likely run into issues where the wrong project gets updated in state. Hence why I'd worry about adding the && alreadyOpenedProject.fsPath
.
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.
Gotcha! Thanks for clarifying! That makes sense!
This error is fixed as part of this PR, but silencing Anyway, I'm happy to merge this PR and move forward with finishing my PR. It still needs some improvements, but we might as well get rid of this |
I have resolved the feedback on my PR #293 and if approved can be merged. Thanks for the help @AryamanAgrawalIronclad but this can be closed. |
Thanks @AryamanAgrawalIronclad I've merged the other PR which fixes the root problem! |
Sounds good! Thanks for finding the right solve! |
File > Open Project
we were encountering an undefined value when trying to parsealreadyOpenedProject.fsPath
fsPath
exists inalreadyOpenedProject
Error:
