Flutter-Bounty-Hunters / static_shock

A static site generator for Dart.
MIT License
58 stars 5 forks source link

[Shock][CLI] - Support offline mode #128

Open suragch opened 1 month ago

suragch commented 1 month ago

Static Shock allows users to serve and update the content dynamically during development using the shock serve CLI command. However, it only works when there is an internet connection. This makes it inconvenient to continue development on a flight or other occasions when internet connectivity is unavailable.

Reproduction steps:

  1. Generate a new Static Shock project.
  2. Disconnect from the internet.
  3. Run shock serve.

Expected result:

The server runs locally and serves the site content at http://localhost:4000/.

Actual result:

An unhandled ClientException is thrown.

The following is the full error message and stack trace:

Unhandled exception:
ClientException with SocketException: Failed host lookup: 'pub.dev' (OS Error: nodename nor servname provided, or not known, errno = 8), uri=https://pub.dev/api/packages/static_shock_cli
#0      IOClient.send (package:http/src/io_client.dart:154:7) <asynchronous suspension>
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:32) <asynchronous suspension>
#2      _withClient (package:http/http.dart:167:12) <asynchronous suspension>
#3      PubUpdater._getPackageInfo (package:pub_updater/src/pub_updater.dart:87:22) <asynchronous suspension>
#4      PubUpdater.getLatestVersion (package:pub_updater/src/pub_updater.dart:57:25) <asynchronous suspension>
#5      StaticShockCliVersion.isAtLeastUpToDateWithPub (package:static_shock_cli/src/version_check.dart:42:27) <asynchronous suspension>
#6      PubVersionCheck.run (package:static_shock_cli/src/version_check.dart:23:24) <asynchronous suspension>
#7      ServeCommand.run (package:static_shock_cli/src/commands/serve_command.dart:45:5) <asynchronous suspension>
#8      CommandRunner.runCommand (package:args/command_runner.dart:212:13) <asynchronous suspension>
#9      main (file:///Users/suragch/.pub-cache/hosted/pub.dev/static_shock_cli-0.0.7/bin/static_shock_cli.dart:26:5) <asynchronous suspension>

Resolving ambiguities

It is unclear at this point if the issue is related to SS itself or Dart. If something about running the Dart server requires contacting pub.dev, then the expected result would be to gracefully handle the exception and inform the user that shock serve only works with an internet connection.

shock build does not throw an exception when there is no internet connection.

suragch commented 4 weeks ago

@matthew-carroll Updated this issue in accordance with the following: