flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
166.31k stars 27.52k forks source link

flutter --version fails when offline #96285

Open mit-mit opened 2 years ago

mit-mit commented 2 years ago

Repro steps

  1. Download a stable macOS build from the releases page: https://docs.flutter.dev/development/tools/sdk/releases

  2. Go offline (turn off wifi and anyther other network connection)

  3. Extract the downloaded zip (e.g. ~/tmp/flutter)

  4. Open a terminal, and run ~/tmp/flutter/bin/flutter --version

Actual result

$ ~/tmp/flutter/bin/flutter --version
VersionCheckError: Command exited with code 128: git fetch
__flutter_version_check__ stable
Standard error: fatal: unable to access
'https://github.com/flutter/flutter.git/': Could not resolve host: github.com

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
mit-macbookpro4:~ mit$

Expected result|

No error.

maheshj01 commented 2 years ago

Hi @mit-mit, Thanks for filing the issue. I am able to reproduce the issue with the newly downloaded sdk.

mahesh@Maheshs-MacBook-Air-M1 ~ % ~/Downloads/flutter/bin/flutter --version
VersionCheckError: Command exited with code 128: git fetch
__flutter_version_check__ stable
Standard error: fatal: unable to access
'https://github.com/flutter/flutter.git/': Could not resolve host: github.com

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (4 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1
mahesh@Maheshs-MacBook-Air-M1 ~ % 
christopherfujino commented 2 years ago

So technically, the command did not fail, as it still printed out the version:

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

This error is actually not coming from the --version code, but actually the tool will periodically check if there is a newer version available upstream. Any time it does this check but the git fetch fails, we print the git error message to stderr as a warning, in case their git repo is misconfigured.

mit-mit commented 2 years ago

OK, let me rephrase: "seems like it fails when offline". The output is very confusing and error like. Can we at least trim it down a bit and make it look less like some random error was thrown? E.g.:

$ ~/tmp/flutter/bin/flutter --version
Warning: Flutter version check failed. Could not resolve host: github.com

Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 77d935af4d (3 weeks ago) • 2021-12-16 08:37:33 -0800
Engine • revision 890a5fca2e
Tools • Dart 2.15.1

Even better, could the flutter tool do an actual check for offline? I suspect we could create a small plugin that calls into OS apis for this (e.g. SCNetworkReachability on macOS)?