-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Prevent App crash when report participant personal details do not exist #17625
Conversation
@PauloGasparSv Please copy/paste the Reviewer Checklist from here into a new comment on this PR and complete it. If you have the K2 extension, you can simply click: [this button] |
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 there is no harm in doing this. Thanks!
src/libs/SidebarUtils.js
Outdated
@@ -230,7 +230,7 @@ function getOptionData(reportID) { | |||
}; | |||
|
|||
const participantPersonalDetailList = _.values(OptionsListUtils.getPersonalDetailsForLogins(report.participants, personalDetails)); | |||
const personalDetail = participantPersonalDetailList[0] || {}; | |||
const personalDetail = participantPersonalDetailList[0] || {login: ''}; |
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 don't particularly care for this solution. The reason is that when using default values in JS, we always use the absolute most simple default value. Please don't ask me why, I have no idea, it's just what is done and has been done for many many years, so let's keep it consistent! My guess is that you could go down some long rabbit hole of trying to provide a default value for every property that could exist on the personalDetail
and it would become a mess. Once we have typescript, this problem will go away.
The way I would fix it is further down and make this change:
PREFERRED:
const login = Str.removeSMSDomain(personalDetail.login || '');
OR:
const login = personalDetail.login ? Str.removeSMSDomain(personalDetail.login) : '';
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.
Once we have typescript, this problem will go away.
How? Because personal details will be a "type" with its defaults, so this won't even be a problem?
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 how it will work is something like your IDE will throw an error (probably where the .replace()
is happening) that login
can be undefined and needs to be protected. This is because personalDetail
will be a strictly defined type.
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.
Cool, eager for this to happen! 🙏
Updated & retested |
Reviewer Checklist
Screenshots/VideosTested with the search screen an seems to work good! |
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.
Tested and updated the tests/ Qa steps to be easier for QA to follow. Thanks!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to staging by https://github.com/mountiny in version: 1.3.3-0 🚀
|
🚀 Deployed to production by https://github.com/mountiny in version: 1.3.3-2 🚀
|
Details
I ran into the issue linked below when developing. I don't know why/how, but I have a shared chat report with an accountID that does not exist in my database, probably/hopefully a dev mistake. However, if at this point in the code we don't have a
participantPersonalDetailList[0]
, I think it's preferable to not let the App fully crash and be unusable rather than have a strange default of{}
which makes the app crash inStr.removeSMSDomain
due to the undefinedpersonalDetail.login
.I will complete the PR checklist when/if you tell me that you agree with this PR 🙃
Fixed Issues
$ https://expensify.slack.com/archives/C049HHMV9SM/p1677597902352659?thread_ts=1677597830.140959&cid=C049HHMV9SM
Tests
Offline tests
N/A
QA Steps
Same as tests
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)src/languages/*
files and using the translation methodWaiting for Copy
label for a copy review on the original GH to get the correct copy.STYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)/** comment above it */
this
properly so there are no scoping issues (i.e. foronClick={this.submit}
the methodthis.submit
should be bound tothis
in the constructor)this
are necessary to be bound (i.e. avoidthis.submit = this.submit.bind(this);
ifthis.submit
is never passed to a component event handler likeonClick
)StyleUtils.getBackgroundAndBorderStyle(themeColors.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Web
Mobile Web - Chrome
Mobile Web - Safari
Desktop
iOS
Android