leoafarias / fvm

Flutter Version Management: A simple CLI to manage Flutter SDK versions.
https://fvm.app
MIT License
4.59k stars 226 forks source link

[BUG] dependency overrides cause malfunction in fvm commands #683

Open kputh opened 6 months ago

kputh commented 6 months ago

Before creating a bug report please make check the following

Describe the bug Commands like fvm use fail with a complicated error message when specific dependency overrides are present.

Example dependency override in pubspec.yaml:

dependency_overrides:
  geolocator_android:
    hosted:
      name: geolocator_android
      url: https://hanntech-gmbh.gitlab.io/free2pass/flutter-geolocator-floss

Example error message:

$ fvm use 3.10.4 --verbose

Argument information:
  Top level options:
  - verbose: true

Command: use

Searching for project in /Users/kaiputh/Downloads/faulty_override/fluffychat

Unhandled exception:
type 'Null' is not a subtype of type 'String'
#0      new ExternalHostedReference.fromJson (package:pubspec/src/dependency.dart:138)
#1      new DependencyReference.fromJson (package:pubspec/src/dependency.dart:25)
#2      new PubSpec.fromJson.<anonymous closure> (package:pubspec/src/pubspec.dart:107)
#3      JsonParser.mapValues.<anonymous closure> (package:pubspec/src/json_utils.dart:113)
#4      MapBase.forEach (dart:collection/maps.dart:35)
#5      JsonParser.mapValues (package:pubspec/src/json_utils.dart:112)
#6      new PubSpec.fromJson (package:pubspec/src/pubspec.dart:110)
#7      new PubSpec.fromYamlString (package:pubspec/src/pubspec.dart:120)
#8      Project.loadFromPath (package:fvm/src/models/project_model.dart:75)
#9      ProjectService.findAncestor (package:fvm/src/services/project_service.dart:42)
#10     UseCommand.run (package:fvm/src/commands/use_command.dart:69)
#11     CommandRunner.runCommand (package:args/command_runner.dart:212)
#12     FvmCommandRunner.runCommand (package:fvm/src/runner.dart:235)
#13     FvmCommandRunner.run (package:fvm/src/runner.dart:117)
#14     main.<anonymous closure> (file:///private/tmp/fvm-20240307-64738-1l9q2g/fvm-3.0.13/bin/main.dart:13)
#15     _rootRun (dart:async/zone.dart:1399)
#16     _CustomZone.run (dart:async/zone.dart:1301)
#17     _runZoned (dart:async/zone.dart:1804)
#18     runZoned (dart:async/zone.dart:1747)
#19     Scope.run (package:scope/src/scope.dart:151)
#20     main (file:///private/tmp/fvm-20240307-64738-1l9q2g/fvm-3.0.13/bin/main.dart:13)
#21     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295)
#22     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184)

To Reproduce

git clone https://github.com/krille-chan/fluffychat.git
cd fluffychat 
fvm use 3.10.4

Then, remove the dependency override for _geolocatorandroid from pubspec.yaml and run fvm use 3.10.4again.

Expected behavior The command should complete successfully.

Desktop:

$ fvm --version
3.0.13
$ fvm doctor 
FVM Doctor:                                                                     
--------------------------------------------------------------------------------
Project:
┌─────────────────────────────┬─────────────────────────────────────────────────────┐
│ Project                     │ fluffychat                                          │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Directory                   │ /Users/kaiputh/Downloads/faulty_override/fluffychat │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Active Flavor               │ None                                                │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Is Flutter Project          │ Yes                                                 │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Dart Tool Generator Version │ Not available                                       │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Dart tool version           │ Not available                                       │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ .gitignore Present          │ Yes                                                 │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Config Present              │ No                                                  │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Pinned Version              │ None                                                │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Config path                 │ .fvmrc                                              │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Local cache dir             │ .fvm/versions                                       │
├─────────────────────────────┼─────────────────────────────────────────────────────┤
│ Version symlink             │ .fvm/versions                                       │
└─────────────────────────────┴─────────────────────────────────────────────────────┘

IDEs:
┌────────────────────────────────┬─────────────────────────────────────────────────────┐
│ IDEs                           │ Value                                               │
├────────────────────────────────┼─────────────────────────────────────────────────────┤
│ VSCode                         │                                                     │
├────────────────────────────────┼─────────────────────────────────────────────────────┤
│ VSCode                         │ No .vscode directory found                          │
├────────────────────────────────┼─────────────────────────────────────────────────────┤
│ IntelliJ (Android Studio, ...) │                                                     │
├────────────────────────────────┼─────────────────────────────────────────────────────┤
│ IntelliJ (Android Studio, ...) │ No local.properties file found in android directory │
├────────────────────────────────┼─────────────────────────────────────────────────────┤
│ IntelliJ (Android Studio, ...) │ No .idea folder found                               │
└────────────────────────────────┴─────────────────────────────────────────────────────┘

Environment:
┌────────────────────────┬────────────────────────────────────┐
│ Environment Variables  │ Value                              │
├────────────────────────┼────────────────────────────────────┤
│ Flutter PATH           │ /Users/kaiputh/flutter/bin/flutter │
├────────────────────────┼────────────────────────────────────┤
│ Dart PATH              │ /Users/kaiputh/flutter/bin/dart    │
├────────────────────────┼────────────────────────────────────┤
│ FVM_CACHE_PATH         │ N/A                                │
├────────────────────────┼────────────────────────────────────┤
│ FVM_USE_GIT_CACHE      │ N/A                                │
├────────────────────────┼────────────────────────────────────┤
│ FVM_GIT_CACHE_PATH     │ N/A                                │
├────────────────────────┼────────────────────────────────────┤
│ FVM_FLUTTER_URL        │ N/A                                │
├────────────────────────┼────────────────────────────────────┤
│ FVM_PRIVILEDGED_ACCESS │ N/A                                │
├────────────────────────┼────────────────────────────────────┤
│ Flutter PATH           │ /Users/kaiputh/flutter/bin/flutter │
├────────────────────────┼────────────────────────────────────┤
│ Dart PATH              │ /Users/kaiputh/flutter/bin/dart    │
└────────────────────────┴────────────────────────────────────┘
┌──────────────┬────────────────────────────────────────────────────────────────┐
│ Platform     │ Value                                                          │
├──────────────┼────────────────────────────────────────────────────────────────┤
│ OS           │ macos Version 13.6.4 (Build 22G513)                            │
├──────────────┼────────────────────────────────────────────────────────────────┤
│ Dart Locale  │ de-DE                                                          │
├──────────────┼────────────────────────────────────────────────────────────────┤
│ Dart runtime │ 3.2.6 (stable) (Wed Jan 24 13:41:58 2024 +0000) on "macos_x64" │
└──────────────┴────────────────────────────────────────────────────────────────┘
suxoikorm commented 4 months ago

Same problem but I don't have dependency overrides, i have self hosted pub packages

some_package: hosted: https://self.hosted.pub.com/

When I removed this packages everything works, but with this packages I have same error.

leoafarias commented 4 months ago

I just checked the repo, and it seems that this is "invalid" for the hosted dependency. I did further research and found the following:

https://github.com/j4qfrost/pubspec/issues/3