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

[$1000] Attachment - No feedback or error message when choosing invalid image file to be sent on chat #19728

Closed
1 of 6 tasks
kbecciv opened this issue May 28, 2023 · 121 comments
Closed
1 of 6 tasks
Assignees
Labels
Bug Something is broken. Auto assigns a BugZero manager. Engineering Internal Requires API changes or must be handled by Expensify staff Monthly KSv2 Not a priority Reviewing Has a PR in review

Comments

@kbecciv
Copy link

kbecciv commented May 28, 2023

If you haven’t already, check out our contributing guidelines for onboarding and email [email protected] to request to join our Slack channel!


Action Performed:

  1. Open the Expensify app on the web browser
  2. Go to any chat conversation
  3. Click on the "+" icon(actions button) of the chat
  4. Click on Add attachment
  5. Select an invalid or corrupted image file from the file explorer(you can create invalid image file by changing any .txt or .pdf file to .jpg simply or you can find sample invalid image attached in thread)
  6. Observe the infinite loading

Expected Result:

The app should display a feedback or error message indicating that the file is not valid or just upload and send as a file without trying to display preview(if the image file is invalid)

Actual Result:

The app does not show any feedback or error message and tries to preview the image file with infinite loading

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android / native
  • Android / Chrome
  • iOS / native
  • iOS / Safari
  • MacOS / Chrome / Safari
  • MacOS / Desktop

Version Number: 1.3.19.2

Reproducible in staging?: yes

Reproducible in production?: yes

If this was caught during regression testing, add the test name, ID and link from TestRail:

Email or phone of affected tester (no customers):

Logs: https://stackoverflow.com/c/expensify/questions/4856

Notes/Photos/Videos: Any additional supporting documentation

no.feedback.mp4
Recording.2865.mp4

Expensify/Expensify Issue URL:

Issue reported by: @KALLL

Slack conversation: https://expensify.slack.com/archives/C049HHMV9SM/p1685001824882209

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~01764cde9077e5564b
  • Upwork Job ID: 1664297284350144512
  • Last Price Increase: 2023-07-14
@kbecciv kbecciv added Daily KSv2 Bug Something is broken. Auto assigns a BugZero manager. labels May 28, 2023
@melvin-bot
Copy link

melvin-bot bot commented May 28, 2023

Triggered auto assignment to @sonialiap (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

@melvin-bot
Copy link

melvin-bot bot commented May 28, 2023

Bug0 Triage Checklist (Main S/O)

  • This "bug" occurs on a supported platform (ensure Platforms in OP are ✅)
  • This bug is not a duplicate report (check E/App issues and #expensify-bugs)
    • If it is, comment with a link to the original report, close the issue and add any novel details to the original issue instead
  • This bug is reproducible using the reproduction steps in the OP. S/O
    • If the reproduction steps are clear and you're unable to reproduce the bug, check with the reporter and QA first, then close the issue.
    • If the reproduction steps aren't clear and you determine the correct steps, please update the OP.
  • This issue is filled out as thoroughly and clearly as possible
    • Pay special attention to the title, results, platforms where the bug occurs, and if the bug happens on staging/production.
  • I have reviewed and subscribed to the linked Slack conversation to ensure Slack/Github stay in sync

@allroundexperts
Copy link
Contributor

allroundexperts commented May 28, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

For corrupt files, we're showing an infinite loader in the Attachment View.

What is the root cause of that problem?

The root cause of this issue is that we're not validating the file types correctly (based on the magic headers, more about this approach in the alternate section). This causes corrupt files to go through to the AttachmentView component. Further more, in the ImageView component, we're also not using the onError callback like we're using on the PDFView component.

What changes do you think we should make in order to solve the problem?

The simplest solution (without magic header check) is to add a onError handler to the ImageView component here. I'm not sure how the UI should look like exactly once error is encountered but we can keep the error in state and if its true, we can render a message here.

What alternative solutions did you explore? (Optional)

The real solution for this sort of issue IMO is to check the file type based on magic headers of the file instead of relying on the file type extracted from the name. The code for this was added in this PR some time ago but the team decided not to add frontend validation of files until another issue came up.

For reference, here's how Slack deals with a jpg extension file that is actually a text file:
https://github.com/Expensify/App/assets/30054992/bffbd3ed-6d9e-4d85-a06c-001ad31050f4

@melvin-bot melvin-bot bot added the Overdue label May 31, 2023
@sonialiap sonialiap added the External Added to denote the issue can be worked on by a contributor label Jun 1, 2023
@melvin-bot melvin-bot bot changed the title Attachment - No feedback or error message when choosing invalid image file to be sent on chat [$1000] Attachment - No feedback or error message when choosing invalid image file to be sent on chat Jun 1, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 1, 2023

Job added to Upwork: https://www.upwork.com/jobs/~01764cde9077e5564b

@melvin-bot
Copy link

melvin-bot bot commented Jun 1, 2023

Current assignee @sonialiap is eligible for the External assigner, not assigning anyone new.

@melvin-bot
Copy link

melvin-bot bot commented Jun 1, 2023

Triggered auto assignment to Contributor-plus team member for initial proposal review - @aimane-chnaif (External)

@melvin-bot melvin-bot bot added the Help Wanted Apply this label when an issue is open to proposals by contributors label Jun 1, 2023
@melvin-bot
Copy link

melvin-bot bot commented Jun 1, 2023

Triggered auto assignment to @marcaaron (External), see https://stackoverflow.com/c/expensify/questions/7972 for more details.

@sonialiap
Copy link
Contributor

👍 adding External label

@melvin-bot melvin-bot bot removed the Overdue label Jun 1, 2023
@s-alves10
Copy link
Contributor

Proposal

Please re-state the problem that we are trying to solve in this issue.

When attach an invalid image file, the AttachPreview shows an infinite loading without showing any error

What is the root cause of that problem?

We're using the Image component defined here in our ImageView component.

The root cause of this issue is that we don't use onError callback of the Image component in ImageView

<Image
source={{uri: this.props.url}}
isAuthTokenRequired={this.props.isAuthTokenRequired}
// Hide image until finished loading to prevent showing preview with wrong dimensions.
style={this.state.isLoading ? undefined : [styles.w100, styles.h100]}
// When Image dimensions are lower than the container boundary(zoomscale <= 1), use `contain` to render the image with natural dimensions.
// Both `center` and `contain` keeps the image centered on both x and y axis.
resizeMode={this.state.zoomScale > 1 ? Image.resizeMode.center : Image.resizeMode.contain}
onLoadStart={this.imageLoadingStart}
onLoad={this.imageLoad}
/>

<Image
source={{uri: this.props.url}}
isAuthTokenRequired={this.props.isAuthTokenRequired}
style={[styles.h100, styles.w100]}
resizeMode={Image.resizeMode.contain}
onLoadStart={this.imageLoadingStart}
onLoad={this.imageLoad}
/>

In addition, we didn't explicitly add onError props to its propTypes here

What changes do you think we should make in order to solve the problem?

We have to add onError props to the Image component explicitly and use it in our ImageView component. In onError callback, we need to do something like

    this.setState({isLoading: false, loadingError: 'Failed to load image'});

and show error message instead of loading indicator.

Result
mac_chrome_19728.mp4

What alternative solutions did you explore? (Optional)

@melvin-bot melvin-bot bot added the Overdue label Jun 5, 2023
@marcaaron
Copy link
Contributor

@aimane-chnaif can you take a look at the proposals so far?

@melvin-bot melvin-bot bot removed the Overdue label Jun 5, 2023
@aimane-chnaif
Copy link
Contributor

The root cause is correct in both proposals.
Showing user feedback on error callback is simple solution but will not fix issue completely. After sending attachment, nothing shows in chat, so we might want to fix that as well here.
I tend to agree with @allroundexperts's alternative solution as a permanent solution. So add logic of detecting real file type, not just from file name and extension. This will be complex solution and may require backend update as well.
@marcaaron what do you suggest?

@s-alves10
Copy link
Contributor

@aimane-chnaif
We're using Image component of react-native and I think we should use error handling of the component. This is good for consistency as well.

What if a file is marked valid in our engine but can't be shown in Image view? Or inverse case?
We can show error message for Image can't render: Invalid or not supported image format

@aimane-chnaif
Copy link
Contributor

aimane-chnaif commented Jun 6, 2023

What if a file is marked valid in our engine but can't be shown in Image view

@s-alves10 I can't think of that case but we can show placeholder icon. That will be consistent with preview after sent to chat.
I checked other social platforms (slack, skype, whatsapp), but don't see any error message. They treat this either as normal file, or as image but showing placeholder or "No preview available".

Btw your proposal is already a dupe and won't be accepted unless you have better solution.

@melvin-bot
Copy link

melvin-bot bot commented Jun 8, 2023

📣 It's been a week! Do we have any satisfactory proposals yet? Do we need to adjust the bounty for this issue? 💸

@melvin-bot melvin-bot bot added the Overdue label Jun 8, 2023
@marcaaron
Copy link
Contributor

@aimane-chnaif can you summarize what you think we should do for this one? When you believe we're ready to move forward with something I will share my thoughts on that proposal, thanks!

@melvin-bot melvin-bot bot removed the Overdue label Jun 8, 2023
@KALLL
Copy link

KALLL commented Jun 10, 2023

Proposal

Please re-state the problem that we are trying to solve in this issue.

The bug is that when the user attaches an image file that is invalid or corrupted, the app tries to display a preview of the image and takes forever. The expected behavior is that the app should display a feedback or error message indicating that the file is not valid, or just upload and send the file as a file without trying to display a preview.

What is the root cause of that problem?

The root cause of the problem is we are not handling onError well on the

<Image
source={{uri: this.props.url}}
isAuthTokenRequired={this.props.isAuthTokenRequired}
// Hide image until finished loading to prevent showing preview with wrong dimensions.
style={this.state.isLoading ? undefined : [styles.w100, styles.h100]}
// When Image dimensions are lower than the container boundary(zoomscale <= 1), use `contain` to render the image with natural dimensions.
// Both `center` and `contain` keeps the image centered on both x and y axis.
resizeMode={this.state.zoomScale > 1 ? Image.resizeMode.center : Image.resizeMode.contain}
onLoadStart={this.imageLoadingStart}
onLoad={this.imageLoad}
/>

What changes do you think we should make in order to solve the problem?

  • Import the icon.png file

import icon from '../images/placeholder-image.png';

  • Define a state variable that will store the real file
this.state = {
  realFile: null
}
  • Define a function that will handle the file selection
handleFileSelect = (event) => {
  // Get the selected file from the event
  const file = event.target.files[0];
  // Set the realFile state to the selected file
  this.setState({realFile: file});
  // Set the image source to the file URL
  this.setState({imageSource: {uri: URL.createObjectURL(file)}});
}
  • Define a function that will handle the image error
handleImageError = () => {
  // Set the image source to placeholder-image.png
  this.setState({imageSource: icon});
}
  • Modify the function that will handle the file upload to assign realFile
handleFileUpload = () => {
  // Get the real file from the state
  const file = this.state.realFile;
  // Check if the file is not null
  if (file) {
    // Upload the file using your preferred method
}    
  }

<input type="file" onChange={this.handleFileSelect} />

What alternative solutions did you explore? (Optional)

Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

@melvin-bot melvin-bot bot added Monthly KSv2 and removed Weekly KSv2 labels Sep 25, 2023
@melvin-bot
Copy link

melvin-bot bot commented Sep 25, 2023

This issue has not been updated in over 15 days. @MariaHCD, @sonialiap, @aimane-chnaif eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

@sonialiap
Copy link
Contributor

@youssef-lr I am not sure how to check, has this PR been opened to contributors? #23103 (comment)

@sonialiap sonialiap added Daily KSv2 and removed Monthly KSv2 labels Nov 3, 2023
Copy link

melvin-bot bot commented Nov 13, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...

Copy link

melvin-bot bot commented Nov 13, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Huh... This is 4 days overdue. Who can take care of this?

Copy link

melvin-bot bot commented Nov 21, 2023

@MariaHCD, @sonialiap, @aimane-chnaif 12 days overdue now... This issue's end is nigh!

@aimane-chnaif
Copy link
Contributor

PR is in review. @youssef-lr is OOO until the end of Nov

Copy link

melvin-bot bot commented Nov 29, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Copy link

melvin-bot bot commented Nov 30, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Huh... This is 4 days overdue. Who can take care of this?

Copy link

melvin-bot bot commented Dec 4, 2023

@MariaHCD, @sonialiap, @aimane-chnaif 8 days overdue is a lot. Should this be a Weekly issue? If so, feel free to change it!

@aimane-chnaif
Copy link
Contributor

Hopefully @youssef-lr will finish PR soon

Copy link

melvin-bot bot commented Dec 12, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

Copy link

melvin-bot bot commented Dec 14, 2023

@MariaHCD, @sonialiap, @aimane-chnaif Eep! 4 days overdue now. Issues have feelings too...

@MariaHCD MariaHCD assigned youssef-lr and unassigned MariaHCD Dec 14, 2023
@youssef-lr
Copy link
Contributor

Sorry, I'm working on higher priority issues. But I should pick this up again either this week or the next one.

@youssef-lr youssef-lr added Weekly KSv2 and removed Daily KSv2 labels Dec 14, 2023
@melvin-bot melvin-bot bot removed the Weekly KSv2 label Jan 8, 2024
Copy link

melvin-bot bot commented Jan 8, 2024

This issue has not been updated in over 15 days. @youssef-lr, @sonialiap, @aimane-chnaif eroding to Monthly issue.

P.S. Is everyone reading this sure this is really a near-term priority? Be brave: if you disagree, go ahead and close it out. If someone disagrees, they'll reopen it, and if they don't: one less thing to do!

Copy link

melvin-bot bot commented Mar 5, 2024

@youssef-lr, @sonialiap, @aimane-chnaif, this Monthly task hasn't been acted upon in 6 weeks; closing.

If you disagree, feel encouraged to reopen it -- but pick your least important issue to close instead.

@melvin-bot melvin-bot bot closed this as completed Mar 5, 2024
@github-project-automation github-project-automation bot moved this from LOW to CRITICAL in [#whatsnext] #vip-vsb Mar 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something is broken. Auto assigns a BugZero manager. Engineering Internal Requires API changes or must be handled by Expensify staff Monthly KSv2 Not a priority Reviewing Has a PR in review
Projects
No open projects
Status: CRITICAL
Development

No branches or pull requests