Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
buchen opened this issue Feb 13, 2024 · 24 comments
Assignees
Labels
bug Something isn't working question Further information is requested

Comments

@buchen
Copy link

buchen commented Feb 13, 2024

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'.

  • Remove the my custom lint package does not make a difference
  • Clearing the pub cache locally does not reproduce the issue

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
@buchen buchen added the bug Something isn't working label Feb 13, 2024
@rrousselGit
Copy link
Collaborator

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

@rrousselGit rrousselGit added the question Further information is requested label Feb 13, 2024
@buchen
Copy link
Author

buchen commented Feb 13, 2024

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:

  • custom_lint = 0.5.11
  • custom_lint_builder = 0.5.14

But downgrading these version fixes the issue:

  • custom_lint = 0.5.8
  • custom_lint_builder = 0.5.10

@buchen
Copy link
Author

buchen commented Feb 13, 2024

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: c5fccae
With the next commit, it starts failing: 346824c
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
Copy link

mgrv-yhlee commented Feb 14, 2024

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
Copy link
Author

buchen commented Feb 14, 2024

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
Copy link
Collaborator

Could you share a small repository to reproduce the issue?

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

@re-ckart
Copy link

@rrousselGit I have the same problem in my project. Here is a repository that showcases the issue. re-ckart/dart_custom_lint_gh_action_error#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
Copy link
Collaborator

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

@re-ckart
Copy link

@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
Copy link

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-[10](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:11)19-azure
    • Chrome (web)    • chrome • web-javascript • Google Chrome [12](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:13)1.0.6[16](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:17)7.[18](https://github.com/gbassisp/flutter_dev_toys/actions/runs/7996396291/job/21839120638#step:6:19)4

[✓] 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
Copy link

@rrousselGit Are there any updates regarding this issue?

@S-ecki
Copy link

S-ecki commented Mar 1, 2024

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
Copy link

dkbast commented Apr 18, 2024

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
Copy link

devj3ns commented Apr 27, 2024

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

@acoutts
Copy link

acoutts commented Aug 30, 2024

I'm having the same issue after bumping flutter from 3.19 to 3.24.1

custom_lint: ^0.6.5
custom_lint:
  rules:
    - avoid_public_notifier_properties: false
    - provider_parameters: true

Nothing else changed in the project except the flutter version. The dart analyze command fails now with:

Analyzing lib, test...                  
An unexpected error was encountered by the Analysis Server.
Please file an issue at https://github.com/dart-lang/sdk/issues/new/choose with the following details:

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: Error: Undefined name 'createPlugin'.
    {'riverpod_lint': riverpod_lint.createPlugin,
                                    ^^^^^^^^^^^^
lib/custom_lint_client.dart:11:3: Error: Method not found: 'runSocket'.
  runSocket(
  ^^^^^^^^^


An unexpected error was encountered by the Analysis Server.
Please file an issue at https://github.com/dart-lang/sdk/issues/new/choose with the following details:

Failed to start plugins

@provokateurin
Copy link

I just started to experience this too after upgrading to custom_lint 0.6.6: nextcloud/neon#2398 (review)

@rrousselGit
Copy link
Collaborator

This should be fixed in 0.6.7.

@provokateurin
Copy link

Just tried it, still the same error. Please re-open the issue

@provokateurin
Copy link

The fact that it only started with ^0.6.6 and I can consistently reproduce it and fix it by downgrading to 0.6.5 strongly indicates to me that the changes of 0.6.6 cause the problem or make it happen more often/in more cases than before.

@rrousselGit rrousselGit reopened this Sep 8, 2024
@rrousselGit
Copy link
Collaborator

rrousselGit commented Sep 8, 2024

0.6.6 most likely has nothing to do with it. It's instead likely caused by some transitive dependency

But regardless, I doubt that custom_lint is the problem here in its current state.
To begin with, flutter analyze shouldn't be running custom_lint code at all. The fact that it tries to run custom_lint is a bug from flutter analyze. Afterall, even though it starts custom_lint, it doesn't care to wait for its result 🤷

@provokateurin
Copy link

provokateurin commented Sep 8, 2024

Checkout this:

diff --git a/packages/neon_framework/example/pubspec.lock b/packages/neon_framework/example/pubspec.lock
index da7d9765b..638c34b89 100644
--- a/packages/neon_framework/example/pubspec.lock
+++ b/packages/neon_framework/example/pubspec.lock
@@ -241,18 +241,18 @@ packages:
     dependency: "direct dev"
     description:
       name: custom_lint
-      sha256: "4939d89e580c36215e48a7de8fd92f22c79dcc3eb11fda84f3402b3b45aec663"
+      sha256: "6e1ec47427ca968f22bce734d00028ae7084361999b41673291138945c5baca0"
       url: "https://pub.dev"
     source: hosted
-    version: "0.6.5"
+    version: "0.6.7"
   custom_lint_builder:
     dependency: transitive
     description:
       name: custom_lint_builder
-      sha256: d9e5bb63ed52c1d006f5a1828992ba6de124c27a531e8fba0a31afffa81621b3
+      sha256: ba2f90fff4eff71d202d097eb14b14f87087eaaef742e956208c0eb9d3a40a21
       url: "https://pub.dev"
     source: hosted
-    version: "0.6.5"
+    version: "0.6.7"
   custom_lint_core:
     dependency: transitive
     description:
diff --git a/packages/neon_framework/example/pubspec.yaml b/packages/neon_framework/example/pubspec.yaml
index 8f77c7b9f..8fee3ed80 100644
--- a/packages/neon_framework/example/pubspec.yaml
+++ b/packages/neon_framework/example/pubspec.yaml
@@ -41,7 +41,7 @@ dependencies:
   vector_graphics: any
 
 dev_dependencies:
-  custom_lint: 0.6.5
+  custom_lint: 0.6.7
   neon_lints:
     git:
       url: https://github.com/nextcloud/neon

I first pinned custom_lint to 0.6.5 and ran pub upgrade in the package.
Then I updated the pinned version to 0.6.7 and the lockfile shows no other dependency was updated alongside it (also not after another pub upgrade).

So no transitive dependency can be the cause for it as nothing changed.

@rrousselGit
Copy link
Collaborator

Your pubspec.lock has no impact on this error. Plugins are ran in a different context, and the analyzer server manually calls pub get.

And this isn't a new issue by any means. The problem is caused by a race condition in dart analyze. It all depends on how fast custom_lint and dart analyze are.
For example, if you don't have the issue with dart analyze but do have it with flutter analyze, that could be because the latter executes at a different speed, so the race condition gets triggered.

Downgrading custom_lint only changes how slow/fast custom_lint is, which may change whether the race condition happens on your computer or not. That doesn't really solve the issue for everyone.

@rrousselGit
Copy link
Collaborator

I'd suggest upvoting dart-lang/sdk#56667 (comment).
That would completely remove the possibility for this issue to happen. But that's a change in dart analyze, not custom-lint.

@provokateurin
Copy link

Ok, thank you for your explanation!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working question Further information is requested
Projects
None yet
Development

No branches or pull requests

10 participants