dart-lang / pub

The pub command line tool
https://dart.dev/tools/pub/cmd
BSD 3-Clause "New" or "Revised" License
1.04k stars 229 forks source link

"Exception type: AliasError" with ISAR and "infinite_scroll_pagination" #3591

Open ziobudda opened 2 years ago

ziobudda commented 2 years ago

I'm using ISAR for my project and now I want to add an infinite scroll pagination, but when I exec

# flutter pub add infinite_scroll_pagination

I receive this error:

ERR : Unsupported operation: Encountered an alias node along [dependencies, isar]! Alias nodes are nodes that refer to a previously serialized nodes, and are denoted by either the "*" or the "&" indicators in the original YAML. As the resulting behavior of mutations on these nodes is not well-defined, the operation will not be supported by this library.
    | 
    | line 4, column 15: The alias was first defined here.
    |   ╷
    | 4 │ isar_version: &isar_version 3.0.1
    |   │               ^^^^^^^^^^^^^^^^^^^
    |   ╵
FINE: Exception type: AliasError
ERR : package:yaml_edit/src/editor.dart 500:34  YamlEditor._assertNoChildAlias
    | package:yaml_edit/src/editor.dart 516:9   YamlEditor._assertNoChildAlias
    | package:yaml_edit/src/editor.dart 484:21  YamlEditor._traverse
    | package:yaml_edit/src/editor.dart 251:24  YamlEditor.update
    | package:pub/src/command/add.dart 413:18   AddCommand._updatePubspec
    | package:pub/src/command/add.dart 174:7    AddCommand.runProtected

In my pubspec.yml I have :

dependencies:
  flutter:
    sdk: flutter

  # The following adds the Cupertino Icons font to your application.
  # Use with the CupertinoIcons class for iOS style icons.
  cupertino_icons: ^1.0.2
  intl: ^0.17.0
  isar: *isar_version
  isar_flutter_libs: *isar_version
  isar_generator: *isar_version
  path_provider: ^2.0.11
  build_runner: any
  google_fonts: ^3.0.1
  dio: ^4.0.6
  flash: ^2.0.3+3
  provider: ^6.0.3
  file_picker: ^5.2.0+1
  open_file: ^2.1.1
  carousel_slider: ^4.1.1
  hovering: ^1.0.4

If I substitute *isar_version with ^3.0.1 all works.

sigurdm commented 1 year ago

pakcage:yaml_edit does not support yaml-references, but we could catch the exception and give a proper error message here.

BansookNam commented 1 year ago

I got the same error when I add "flutter pub add freezed_annotation". Thanks for the message but it is needed to be fixed. 🙏

sigurdm commented 1 year ago

@BansookNam can you make a reproduction?

sigurdm commented 1 year ago

We should give a nicer error message. But I don't think we'll ever have support for the combination of dart pub add and yaml references.

BansookNam commented 1 year ago

@sigurdm I made a flutter project for reproduction. https://github.com/BansookNam/dart_reproduction

You can reproduce this by running 'flutter pub add freezed_annotation'.

This is my flutter doctor [✓] Flutter (Channel stable, 3.10.1, on macOS 13.1 22C65 darwin-arm64, locale en-KR) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.1) [✓] Xcode - develop for iOS and macOS (Xcode 14.2) [✓] Chrome - develop for the web [✓] Android Studio (version 2022.2) [✓] IntelliJ IDEA Community Edition (version 2022.2.4) [✓] VS Code (version 1.78.2) [✓] Connected device (2 available) [✓] Network resources

sigurdm commented 1 year ago

Thanks for the reproduction

Yeah :( - don't expect yaml references to work with dart add anytime soon. Adding that functionality to yaml_edit would be highly non-trivial (it is not clear if an update involving a reference should update the reference or the referencing site).

Consider not using yaml references, or manually editing pubspec.yaml

I believe pub.dev doesn't allow publishing packages with yaml references (as they cannot trivially be represented as json for the version listing api)

@jonasfj should we just make it an error to have yaml references in pubspec.yaml? That would probably be too breaking...

Should we try making_yaml edit work such that if you are updating parts of the file without references things just work?