Skip to content
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: eliminate "Cannot read properties of undefined (reading type)" error #5443

Merged
merged 4 commits into from
Feb 22, 2024

Conversation

daphne-sfdc
Copy link
Contributor

What does this PR do?

Eliminates the "Cannot read properties of undefined (reading type)" error that happens when a user cancels a retrieve.

What issues does this PR fix or reference?

@W-15091722@

Functionality Before

When a user clicks the Cancel button while a retrieve is in progress, they see the "Cannot read properties of undefined (reading type)" error.
Screenshot 2024-02-21 at 10 43 10 AM

Functionality After

When a retrieve is cancelled, there is no error message and the command ends gracefully.
Screenshot 2024-02-21 at 11 59 35 AM

@@ -280,7 +280,7 @@ export abstract class RetrieveExecutor<T> extends DeployRetrieveExecutor<T> {
protected async postOperation(
result: RetrieveResult | undefined
): Promise<void> {
if (result) {
if (result && result.response.fileProperties !== undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done with

Suggested change
if (result && result.response.fileProperties !== undefined) {
if (result?.response?.fileProperties !== undefined) {

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I dont understand this code well enough, but the question that I have is why is the check
result.response.fileProperties !== undefined not at line 288 juts before calling setPropertiesForFilesRetrieve ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put my condition with the other condition because that was where it originally was. It's pretty old code so I just kept the status quo. 🙂

I would assume it's because putting the if statement earlier means Lines 284-288 wouldn't be run unnecessarily.

Co-authored-by: peternhale <peternhale@users.noreply.github.com>
@@ -280,7 +280,7 @@ export abstract class RetrieveExecutor<T> extends DeployRetrieveExecutor<T> {
protected async postOperation(
result: RetrieveResult | undefined
): Promise<void> {
if (result) {
if (result?.response?.fileProperties !== undefined) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if my comment got lost, so reposting.
not knowing the code well enough, a naive question. why is check fileProperties !== undefined not before calling setPropertiesForFilesRetrieve?

Also can setPropertiesForFilesRetrieve be called in other places? which means does this check need to go in setPropertiesForFilesRetrieve ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also as per this fix, everything after line 283 will be skipped even if result is not null . is this expected?

Copy link
Contributor Author

@daphne-sfdc daphne-sfdc Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Copying over above answer - I put my condition with the other condition because that was where it originally was. It's pretty old code so I just kept the status quo. I would assume it's because putting the if statement earlier means Lines 284-288 wouldn't be run unnecessarily.

  2. As of now, setPropertiesForFilesRetrieve() is not called anywhere else, according to a search.
    Screenshot 2024-02-21 at 12 33 16 PM

Copy link
Contributor

@peternhale peternhale Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diyer That is a good point. The check if (result?.response?.fileProperties !== undefined) { guarantees the block will not be executed if any property named is undefined. The previous block ran when result was not undefined, it might be useful to better understand which parts of result are used within the block, including the createOutput call, so see if additional not undefined checks need to be done for each operation within the block. Is createOutput independent of PersistentStorageService.getInstance().setPropertiesForFilesRetrieve WRT individual properties of result.

Copy link
Contributor Author

@daphne-sfdc daphne-sfdc Feb 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a slight difference in the contents of the Output tab. If the check is moved down to Line 289, there will be an extra blank line in the Output tab before the ended statement because output is an empty line and channelService appends it.

That's the only difference that I see - result is not used anywhere else in that block. But I guess it would be nice to clear the error collection in case there's something there?

Screenshot 2024-02-21 at 12 53 09 PM
Screenshot 2024-02-21 at 12 52 37 PM

@daphne-sfdc daphne-sfdc force-pushed the daphne/fix-retrieve-cancel-error branch from 5fbe3f4 to f197108 Compare February 21, 2024 18:14
@daphne-sfdc daphne-sfdc merged commit 56c7f3d into develop Feb 22, 2024
12 checks passed
@daphne-sfdc daphne-sfdc deleted the daphne/fix-retrieve-cancel-error branch February 22, 2024 14:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants