-
Notifications
You must be signed in to change notification settings - Fork 8
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
[static_shock_cli]: Handle SocketException when checking for Pub version (resolves #128) #131
base: main
Are you sure you want to change the base?
Conversation
This issue probably deserves a more holistic approach. We have multiple plugins that talk to the network, too, such as the GitHub plugin. We probably need a concept of an online vs offline mode. I would imagine that trying to run a standard build without internet should fail, but a special offline mode could be requested via arguments. I believe Flutter works that way. Feel free to post thoughts about where we might inject this control. |
In the
And these should fail if there is no internet:
I'm not currently sure what an online/offline mode control would look like that spans both
|
Why not? If build fails I would expect serve to fail. What's the use case where you'd get meaningful value from serve without building the website?
I'm not sure that would be a desirable behavior in general. When build runs, it deletes the existing build first. So if you happen to run without network access and you didn't realize it, you just deleted the version of your website that had the list of contributors. Can you review the Flutter CLI and see how much/little works offline without explicitly telling the CLI to go into offline mode? |
I'd like
Good point. However, this is still
These Flutter CLI commands work while offline:
If you do explicitly allow offline mode (or
These CLI commands don't work:
|
Looks like Flutter can provide local status information without being online. For Static Shock that's just I wasn't completely clear on your last two categories. You mentioned Assuming the following can't be done offline for Flutter...
That would probably map to...
Then, finally, Action Items:
Even though |
Yes, I wasn't very clear with those. The assumptions you made, though, were correct. Additional clarification:
|
Handle
SocketException
when checking for Pub version.static_shock_cli
checks for a newer version of the package onpub.dev
when runningshock serve
. It assumes that the user has an active internet connection, but this is not always the case.While making a GET request when there is no internet connect, the
http
library defines and throws aClientException
. At a lower level, this is adart:io SocketException
. In order to avoid importinghttp
, this PR just handlesSocketException
.When a
SocketException
occurs, the code cancels the Pub check and logs a warning. This allowsstatic_shock_cli
to continue serving the site using the current local version. The alternative would be to abort the serve and tell the user to restore the internet connection. However, that would make for a bad user experience.Issues to consider
StaticShockCliVersion
to test it.UpgradeCommand
andVersionCommand
also check for Pub version updates. I didn't update the code there since that is outside of the scope of issue [Shock][CLI] - Support offline mode #128. However, at leastVersionCommand
should also handle socket exceptions.