invertase / dart_custom_lint

💡 Easily write powerful Dart & Flutter lint rules for your projects or for users of your packages.
https://pub.dev/packages/custom_lint
Apache License 2.0
275 stars 58 forks source link

Error from the analysis server: Couldn't resolve the package 'custom_lint_builder' #228

Open buchen opened 4 months ago

buchen commented 4 months ago

Describe the bug

My projects is using riverpod and has a custom lint sub-package. The issue started to occur after updating custom_lint_builder and custom_lint to version 0.6.0.

Running locally, dart analyze lib runs fine. Running on codemagic CI, however, I get the following error message:

Error from the analysis server: Error: Couldn't resolve the package 'custom_lint_builder' in 'package:custom_lint_builder/src/channel.dart'.

I'd appreciate any hint in which direction to investigate

This is (part of) the verbose output. The ~5.5K output contains the resolution of the packages which all come up to

...

 +389 ms] dart --disable-dart-dev /Users/builder/programs/flutter/bin/cache/dart-sdk/bin/snapshots/analysis_server.dart.snapshot --disable-server-feature-completion --disable-server-feature-search --sdk /Users/builder/programs/flutter/bin/cache/dart-sdk
[   +9 ms] ==> {"id":"1","method":"server.setSubscriptions","params":{"subscriptions":["STATUS"]}}
[        ] ==> {"id":"2","method":"analysis.setAnalysisRoots","params":{"included":["/Users/builder/clone/lib"],"excluded":[]}}
[        ] Analyzing lib...
[ +140 ms] <== {"event":"server.connected","params":{"version":"1.34.0","pid":1727}}
[  +10 ms] <== {"id":"1"}
[+9508 ms] <== {"event":"server.status","params":{"analysis":{"isAnalyzing":true}}}
[+6157 ms] <== {"event":"analysis.errors","params":{"file":"/Users/builder/clone/lib/ui/settings/settings_section.dart","errors":[]}}

...

[        ] <== {"event":"server.error","params":{"isFatal":false,"message":"Error: Couldn't resolve the package 'custom_lint_builder' in 'package:custom_lint_builder/src/channel.dart'.\nError: Couldn't resolve the package 'pp_custom_lint' in 'package:pp_custom_lint/pp_custom_lint.dart'.\nError: Couldn't resolve the package 'riverpod_lint' in 'package:riverpod_lint/riverpod_lint.dart'.\nlib/custom_lint_client.dart:3:8: Error: Not found: 'package:custom_lint_builder/src/channel.dart'\nimport 'package:custom_lint_builder/src/channel.dart';\n       ^\nlib/custom_lint_client.dart:4:8: Error: Not found: 'package:pp_custom_lint/pp_custom_lint.dart'\nimport 'package:pp_custom_lint/pp_custom_lint.dart' as pp_custom_lint;\n       ^\nlib/custom_lint_client.dart:5:8: Error: Not found: 'package:riverpod_lint/riverpod_lint.dart'\nimport 'package:riverpod_lint/riverpod_lint.dart' as riverpod_lint;\n       ^\nlib/custom_lint_client.dart:17:39: Error: Undefined name 'createPlugin'.\n    {'pp_custom_lint': pp_custom_lint.createPlugin,\n                                      ^^^^^^^^^^^^\nlib/custom_lint_client.dart:18:32: Error: Undefined name 'createPlugin'.\n'riverpod_lint': riverpod_lint.createPlugin,\n                               ^^^^^^^^^^^^\nlib/custom_lint_client.dart:12:3: Error: Method not found: 'runSocket'.\n  runSocket(\n  ^^^^^^^^^\n","stackTrace":""}}
[   +2 ms] Error from the analysis server: Error: Couldn't resolve the package 'custom_lint_builder' in 'package:custom_lint_builder/src/channel.dart'.
           Error: Couldn't resolve the package 'pp_custom_lint' in 'package:pp_custom_lint/pp_custom_lint.dart'.
           Error: Couldn't resolve the package 'riverpod_lint' in 'package:riverpod_lint/riverpod_lint.dart'.
           lib/custom_lint_client.dart:3:8: Error: Not found: 'package:custom_lint_builder/src/channel.dart'
           import 'package:custom_lint_builder/src/channel.dart';
                  ^
           lib/custom_lint_client.dart:4:8: Error: Not found: 'package:pp_custom_lint/pp_custom_lint.dart'
           import 'package:pp_custom_lint/pp_custom_lint.dart' as pp_custom_lint;
                  ^
           lib/custom_lint_client.dart:5:8: Error: Not found: 'package:riverpod_lint/riverpod_lint.dart'
           import 'package:riverpod_lint/riverpod_lint.dart' as riverpod_lint;
                  ^
           lib/custom_lint_client.dart:17:39: Error: Undefined name 'createPlugin'.
               {'pp_custom_lint': pp_custom_lint.createPlugin,
                                                 ^^^^^^^^^^^^
           lib/custom_lint_client.dart:18:32: Error: Undefined name 'createPlugin'.
           'riverpod_lint': riverpod_lint.createPlugin,
                                          ^^^^^^^^^^^^
           lib/custom_lint_client.dart:12:3: Error: Method not found: 'runSocket'.
             runSocket(
             ^^^^^^^^^

Flutter version (on stable channel)

flutter --version
Flutter 3.16.9 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 41456452f2 (3 weeks ago) • 2024-01-25 10:06:23 -0800
Engine • revision f40e976bed
Tools • Dart 3.2.6 • DevTools 2.28.5
rrousselGit commented 4 months ago

I can't help with the limited information given. I'd need a complete example

But it sounds to me like you're missing a pub get or have incorrectly installed your dependencies. The error is complaining about unresolved imports afterall

buchen commented 4 months ago

I'd need a complete example

@rrousselGit Fair. For what it's worth, here is the full error log: issue228_full_log.txt

It looks to me that the dependency resolution works, but somehow something is different in the environment on the build server and it does not get passed to the analysis server.

BTW, downgrading to this version shows the same issue:

But downgrading these version fixes the issue:

buchen commented 4 months ago

FYI, to narrow it down, I converted the pubspec dependencies to ones pointing to git commits - including some dependencyOverrides - in this style:

  custom_lint:
    git:
      url: https://github.com/invertase/dart_custom_lint.git
      ref: c5fccae54fa305d60302f453f8b192f7b51977ea
      path: packages/custom_lint

This commit still does work: c5fccae54fa305d60302f453f8b192f7b51977ea With the next commit, it starts failing: 346824c1815f578bfde8410927cea5e59f1d35c2 Which doesn't make any sense to me as (as a newbie to the dart/flutter ecosystem) as the last commit 'only' changes release versions.

mgrv-yhlee commented 4 months ago

I'm having the same problem with Github Actions.

image

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.16.9, on macOS 14.2.1 23C71 darwin-arm64, locale ko-KR) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.2) [✓] Xcode - develop for iOS and macOS (Xcode 15.0.1) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.1) [✓] IntelliJ IDEA Community Edition (version 2023.3.1) [✓] VS Code (version 1.86.0) [✓] Connected device (2 available) [✓] Network resources

dev_dependencies:
  flutter_test:
    sdk: flutter

  flutter_lints: ^3.0.0
  freezed: ^2.4.7
  mockito: 5.4.4
  build_runner: ^2.4.8
  injectable_generator:
  json_serializable: ^6.7.1
  riverpod_generator: ^2.3.11
  riverpod_analyzer_utils: ^0.5.1
  melos: ^3.0.0
  custom_lint: 0.6.0
  custom_lint_builder: 0.6.0
  custom_lint_core: 0.6.0
  riverpod_lint: ^2.3.9
buchen commented 4 months ago

My hack: Because I don't want to do without the Riverpod lints locally, I remove the custom_lint plugin on the build server.

sed -i '' '/custom_lint/d' analysis_options.yaml
flutter analyze lib
rrousselGit commented 4 months ago

Could you share a small repository to reproduce the issue?

I assume your project, with all sources deleted, should be enough

re-ckart commented 4 months ago

@rrousselGit I have the same problem in my project. Here is a repository that showcases the issue. https://github.com/re-ckart/dart_custom_lint_gh_action_error/pull/1

The Github Action fails in the PR with the following error

Error from the analysis server: Error: Couldn't resolve the package 'custom_lint_builder' in 'package:custom_lint_builder/src/channel.dart'.
Error: Couldn't resolve the package 'riverpod_lint' in 'package:riverpod_lint/riverpod_lint.dart'.
lib/custom_lint_client.dart:3:8: Error: Not found: 'package:custom_lint_builder/src/channel.dart'
import 'package:custom_lint_builder/src/channel.dart';
       ^
lib/custom_lint_client.dart:4:8: Error: Not found: 'package:riverpod_lint/riverpod_lint.dart'
import 'package:riverpod_lint/riverpod_lint.dart' as riverpod_lint;
       ^
lib/custom_lint_client.dart:16:[37](https://github.com/re-ckart/dart_custom_lint_gh_action_error/actions/runs/7918129033/job/21615819522?pr=1#step:5:38): Error: Undefined name 'createPlugin'.
    {'riverpod_lint': riverpod_lint.createPlugin,
                                    ^^^^^^^^^^^^
lib/custom_lint_client.dart:11:3: Error: Method not found: 'runSocket'.
  runSocket(
  ^^^^^^^^^

Error from the analysis server: Failed to start plugins
rrousselGit commented 4 months ago

@re-ckart You need to run flutter pub get. Your workflow never does it.

re-ckart commented 4 months ago

@rrousselGit
flutter analyze should run this by default or am I reading the help wrong? $ flutter analyze -h

Usage: flutter analyze [arguments]
-h, --help                    Print this usage information.
    --[no-]current-package    Analyze the current project, if applicable.
                              (defaults to on)
    --watch                   Run analysis continuously, watching the filesystem for changes.
    --write=<file>            Also output the results to a file. This is useful with "--watch" if you want a file to always contain the latest results.      
    --[no-]suggestions        Show suggestions about the current flutter project.
    --[no-]pub                Whether to run "flutter pub get" before executing this command.
                              (defaults to on)

But nevertheless, I updated my workflow to run pub get before analyze and I still get the same error. (see last commit in the PR I linked before)

gbassisp commented 4 months ago

Hey @rrousselGit I'm also getting the same thing and my current solution is to work around it the way @buchen mentioned. I'm posting this reply to give you some more context on the problem.

  1. I only get this on CI (see the workflows I'm posting); it works fine locally on linux and macos
  2. It happens with flutter analyze, but not dart analyze
  3. For me it started on flutter 3.19, but it doesn't seem to be the case for the others?
  4. There is a flutter doctor -v on the "Run Setup" step for more info, but it looks normal to me. CI is using flutter subosito action, maybe the problem is there?
    
    ✓] Flutter (Channel stable, 3.19.1, on Ubuntu 22.04.4 LTS 6.2.0-1019-azure, locale C.UTF-8)
    • Flutter version 3.19.1 on channel stable at /opt/hostedtoolcache/flutter/stable-3.19.1-x64
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision abb292a07e (24 hours ago), 2024-02-20 14:35:05 -0[8](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:9)00
    • Engine revision 04817c[9](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:10)9c9
    • Dart version 3.3.0
    • DevTools version 2.31.1

[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0) • Android SDK at /usr/local/lib/android/sdk • Platform android-34, build-tools 34.0.0 • ANDROID_HOME = /usr/local/lib/android/sdk • ANDROID_SDK_ROOT = /usr/local/lib/android/sdk ✗ Android SDK file not found: adb. • Try re-installing or updating your Android SDK, visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions.

[✓] Chrome - develop for the web • Chrome at google-chrome

[✗] Linux toolchain - develop for Linux desktop • Ubuntu clang version 14.0.0-1ubuntu1.1 • cmake version 3.28.3 ✗ ninja is required for Linux development. It is likely available from your distribution (e.g.: apt install ninja-build), or can be downloaded from https://github.com/ninja-build/ninja/releases • pkg-config version 0.29.2 ✗ GTK 3.0 development libraries are required for Linux development. They are likely available from your distribution (e.g.: apt install libgtk-3-dev)

[!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/linux#android-setup for detailed instructions).

[✓] Connected device (2 available) • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.4 LTS 6.2.0-1019-azure • Chrome (web) • chrome • web-javascript • Google Chrome 121.0.6167.184

[✓] Network resources • All expected network resources are available.



With workaround it passes: https://github.com/gbassisp/flutter_dev_toys/actions/runs/7998286873/job/21844214242
Without it fails: https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638
dart analyze works fine (line 158 of run make web step): https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396202/job/21838777176
re-ckart commented 4 months ago

@rrousselGit Are there any updates regarding this issue?

S-ecki commented 3 months ago

My hack: Because I don't want to do without the Riverpod lints locally, I remove the custom_lint plugin on the build server.

sed -i '' '/custom_lint/d' analysis_options.yaml
flutter analyze lib

As a note to this workaround: For my workflows using ubuntu-latest, I needed to slightly change it to: sed -i '/custom_lint/d' analysis_options.yaml

Nevertheless, I am really thankful for the workaround! Having same issue as people above.

dkbast commented 2 months ago

I ran into the same issue, this is my github workflow, I bumped Flutter stable to 3.19 from the previous stable release and pulled Dart to 3.3 - my guess is that this is where the issue is coming from.

environment:
  sdk: ">=3.3.0 <4.0.0"

  custom_lint: ^0.5.8
  riverpod_lint: ^2.1.1
jobs:
  build:
    runs-on: ubuntu-latest

    permissions: write-all

    steps:
      - uses: actions/checkout@v2

      - uses: subosito/flutter-action@v2.5.0
        with:
          flutter-version: "3.19.5"
          channel: "stable"
          cache: true

      - name: Install Dependencies
        run: flutter packages get

      - name: Format
        run: dart format --set-exit-if-changed lib test

      - name: Analyze
        run: flutter analyze lib test
devj3ns commented 2 months ago

I am experiencing the same issue in my GitHub Action when running dart run custom_lint and flutter analyze lib