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

entry.error(message) gives generic external_client_failure instead of error message #2502

Open
sezaru opened this issue Mar 4, 2023 · 1 comment

Comments

@sezaru
Copy link

sezaru commented Mar 4, 2023

Environment

I want to do some pre-processing (for example, checking the to-be-uploaded image width and height and giving an error if the size is not correct) before I upload a file directly to S3, so I need a way to make the upload fail with a meaningful error instead of a generic one.

  • Elixir version (elixir -v): Elixir 1.14.0 (compiled with Erlang/OTP 23)
  • Phoenix version (mix deps): 1.7.0
  • Phoenix LiveView version (mix deps): 0.18.16
  • Operating system: Pop-OS 22.10
  • Browsers you attempted to reproduce this bug on (the more the merrier): Firefox
  • Does the problem persist after removing "assets/node_modules" and trying again? N/A

Actual behavior

Looking at the live view documentation here https://hexdocs.pm/phoenix_live_view/uploads-external.html in the upchunk uploader implementation, the function entry.error is used to pass an error message as an argument.

Because of that, I'm assuming that you can extract that message somehow, but when I try the same thing like this:

Uploaders.S3 = function(entries, onViewError) {
  entries.forEach(entry => {
    entry.error('my_error_message')
  })
}

I will get the generic :external_client_failure when running upload_errors(@uploads.images, entry) instead of my_error_message string.

Expected behavior

I expect to get my_error_message string as the error message.

@MullPointer
Copy link
Contributor

I have also been looking into this, as I wanted to be able to log errors with client uploads to S3 for troubleshooting reasons.

As far as I can tell, the error reason given to entry.error in your example is sent back to the server, but then not stored anywhere. You can see this in update_progress in Phoenix.LiveView.Upload: reason is not stored.

This was previously noticed as a side issue in issue #1478, with a comment here from @chrismccord that there is "very little you can do on the server if the client fails and we must hold the error reason in memory".

Perhaps in your case you could handle displaying the error messages from pre-processing directly on the client via JavaScript rather than sending the error message via the server. For logging errors, I was considering pushing a custom failure message to the server from the Uploader.

But it would be helpful for there to be a way to access these errors, maybe through a separate external_client_errors list on UploadConfig. This would not be populated if no errors were actually sent by the Uploader JavaScript. Or there could be the option to define a handler function for external client errors on allow_upload.

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

No branches or pull requests

2 participants