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

Add a download failure message, rather than trying to unzip an HTML page #24

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

subdigital
Copy link

What does this change accomplish?

If you try to install a build where the URL it downloads gives you an HTTP 403 response, previously Tophat would ignore the status code and save the resulting response body to the target file. Later it would get a failure trying to unzip this file.

How have you achieved it?

Tophat now looks for a 200 response status code, and if it is not, it reports it as an error. The failure reason is attached to the the error enum so that we can display it to the user.

How can the change be tested?

Open up an install URL to a non-existent AWS S3 bucket:

http://localhost:29070/install/ios?virtual=https://some-bucket-we-dont-have-access-to.s3.us-east-1.amazonaws.com/foo/build.app.zip

See the error like this:

Screenshot 2024-10-08 at 11 25 50 AM

@subdigital subdigital force-pushed the download-failure-error-msg branch from 647a7dc to f5aafae Compare October 8, 2024 19:31
@subdigital
Copy link
Author

I have signed the CLA

Copy link
Member

@lfroms lfroms left a comment

Choose a reason for hiding this comment

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

Thanks, @subdigital! Definitely makes the error message more helpful. Left some questions.

let (localURL, _) = try await URLSession.shared.download(from: url, delegate: self)
let (localURL, response) = try await URLSession.shared.download(from: url, delegate: self)
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0
if statusCode != 200 {
Copy link
Member

Choose a reason for hiding this comment

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

Does this assumption stand for URLs that redirect? I haven't encountered a redirecting URL for any artifacts I've worked with, but being mindful of others that may be relying on this today.

Also, could potentially turn this into a guard.

Copy link
Author

Choose a reason for hiding this comment

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

Redirects are handled implicitly by URLSession, unless you intervene via the delegate.

let (localURL, response) = try await URLSession.shared.download(from: url, delegate: self)
let statusCode = (response as? HTTPURLResponse)?.statusCode ?? 0
if statusCode != 200 {
let body = (try? String(contentsOf: localURL)) ?? "<no response>"
Copy link
Member

Choose a reason for hiding this comment

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

How valuable is the actual response data? It does seem to clutter the alert quite a bit—is the status code enough? To get more granular I wonder if it could be enough to look at the logs via Console. But let me know what you think.

Copy link
Author

Choose a reason for hiding this comment

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

I know what you mean... I can look at sending this to the console and instead showing a generic error for HTTP 403 or 401

@lfroms
Copy link
Member

lfroms commented Dec 7, 2024

Hey @subdigital, apologies for pulling the rug out from under these changes! I spent the last couple of weeks making some architectural changes to Tophat.

HTTP downloads are now handled by HTTPArtifactProvider in TophatCoreExtension, which would be the appropriate place to handle this and throw a LocalizedError. Should be able to move the logic over without too much trouble.

Developers have to change the team ids in order to build and then have to remember to revert these changes before submitting a PR. This moves the definition of DEVELOPMENT_TEAM into a config file that is gitignored.

A bootstrap script is provided to make getting set up easier.
bootstrap.sh is now setup_team.sh and can take a 'default' argument.
Xcode will call this script if the xcconfig file is not present on
disk, making it a zero-setup process for internal contributors.

External contributors will need to run setup_team.sh once to set
up their own team id.
@subdigital subdigital force-pushed the download-failure-error-msg branch from 2a995b3 to efe3c0e Compare December 20, 2024 23:20
@subdigital
Copy link
Author

This PR Builds on top of #59 and re-applies the download error behavior for the new extension system.

To do this I had to move the error enum up a level to TophatFoundation so that extensions could use it and the host app could reference it so the error information could be unwrapped to show the alert.

I also got some weird linker errors about using Logger so I stuck with print() for now. Let me know if this works!

@subdigital
Copy link
Author

image

The new alert looks like this

@lfroms
Copy link
Member

lfroms commented Jan 6, 2025

To do this I had to move the error enum up a level to TophatFoundation so that extensions could use it and the host app could reference it so the error information could be unwrapped to show the alert.

I don't think this is needed. Any LocalizedError-conforming error defined within the extension itself is automatically processed by Tophat when it is thrown. We should be able to produce the error descriptions in the extension like before. Was there an issue you were running into?

I also got some weird linker errors about using Logger so I stuck with print() for now. Let me know if this works!

Yes, that's expected. The logger is unavailable in extensions. We could use print, but in the production build it likely won't route anywhere.

@lfroms
Copy link
Member

lfroms commented Mar 11, 2025

Hi @subdigital, do you still plan to work on this?

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.

2 participants