Skip to content

Error message when failing to resolve package:pedantic include in analysis_options.yaml is not descriptive enough #3259

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

Closed
timsneath opened this issue Apr 6, 2021 · 19 comments
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Milestone

Comments

@timsneath
Copy link
Contributor

See screenshot.

This used to occur regularly, but had gone away for some months. Now it's back again. Could this be a regression?

The include file package:pedantic/analysis_options.yaml in c:\src\win32\analysis_options.yaml cannot be found.

image

@DanTup
Copy link
Member

DanTup commented Apr 6, 2021

I don't seem to be able to repro - though I have some questions:

  • Do you know if the file might not have existed when you opened the project (eg. you later ran Pub Get and we didn't clear the error), or do you think the was there from the start?
  • Ca.n you reproduce it reliably?
  • Is your pubspec.yaml that references pedantic in the same folder as the analysis_options.yaml?

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Apr 6, 2021
@timsneath
Copy link
Contributor Author

timsneath commented Apr 12, 2021 via email

@DanTup
Copy link
Member

DanTup commented Apr 13, 2021

In theory, any analyzer referenced by the project shouldn't impact the analyzer being used by the editor (we always run the snapshot from the SDK), so I suspect not related. Let me know if you can repro though (if you can share a project that is triggering it when you open it, that would be particularly useful).

I'll have a go on Windows too, in case that was a factor (though I suspect not).

@github-actions
Copy link

This issue has been marked stale because it is tagged awaiting-info for 30 days with no activity. Remove the stale label or comment to prevent the issue being closed in 10 days.

@github-actions github-actions bot added the stale Will be closed soon if no response. label May 14, 2021
@DanTup
Copy link
Member

DanTup commented May 17, 2021

@timsneath have you seen this since? I tried to repro on Windows without any luck.

@timsneath
Copy link
Contributor Author

timsneath commented May 17, 2021 via email

@github-actions github-actions bot removed the stale Will be closed soon if no response. label May 18, 2021
@DanTup
Copy link
Member

DanTup commented May 18, 2021

Do you happen to know if it's when you're missing the packages locally (eg. fresh clone and haven't run pub get yet)? What version(s) of the SDKs do you tend to use?

I can't see any obvious causes in the code. If the file exists on disk during analysis ofcourse the error should never be generated. If it doesn't, when when the .packages or .dart_tool/package_config.json files are written it re-creates the analysis contexts which re-triggers analysis of this.

It might be useful to run with the analysis_server log and/or analysis_server instrumentation log enabled, and when you next see it grab a copy of those files so we can see if there are any clues in there.

@timsneath
Copy link
Contributor Author

timsneath commented Jun 2, 2021 via email

@DanTup
Copy link
Member

DanTup commented Jun 9, 2021

I just hit what seems like this problem myself, although what triggered it was a little weird so I'm not sure if it's the same for you.

I opened flutter_gallery and got the same error, even though I could see from the .packages/.dart_tool/package_config.json (and the dependencies tree) that everything was correct. I rigged the analyzer to include the full path of where it was looking for the file in the error message, and that did not match:

Screenshot 2021-06-09 at 11 56 55

I found that I had a codeviewer_cli/.dart_tool/package_config.json file that referenced and old version of pedantic. It looks like that was a nested project that was removed (although the non-git files remained on my disk).

I'm able to reproduce this with a nested project like this:

foo/
    pubspec.yaml <-- references pedantic 1.11.0
    analysis_options.yaml <-- imports package:pedantic/analysis_options.1.11.0.yaml

    example/
        pubspec.yaml <-- references pedantic 1.8.0

If I fetch packages for both projects, I see the warning above because the analysis server seems to use the example/.dart_tool/package_config.json file to resolve the pedantic.

Whilst this initially seemed like a bug, I think actually it may be working as intended (although it's confusing). I don't believe it's using the wrong package file to analyze the analys_options file, I think it's analysing the file twice. Once in the context of the root project (which works, because it uses the package paths from the root project) and then again in the context of the nested project (since it walks up the tree and finds that anlaysis_options file, then tries to pare is using the nested projects package paths).

So although the way the error is reported looks like it's for the root project, it's actually for the context of a nested project.

@bwilkerson assuming this is working as expected, perhaps there's something we could tag onto the error message to make it clearer? Currently it says:

The include file package:pedantic/analysis_options.1.11.0.yaml in /Users/danny/Desktop/dart_application_2/analysis_options.yaml cannot be found.

Perhaps we could tag something onto the end when the analysis_options file is not inside the context? For example:

The include file package:pedantic/analysis_options.1.11.0.yaml in /Users/danny/Desktop/dart_application_2/analysis_options.yaml cannot be found when analyzing /Users/danny/Desktop/dart_application_2/example.

@DanTup DanTup added in lsp/analysis server Something to be fixed in the Dart analysis server in editor Relates to code editing or language features and removed awaiting info Requires more information from the customer to progress labels Jun 9, 2021
@DanTup DanTup added this to the v3.24.0 milestone Jun 9, 2021
@bwilkerson
Copy link

Yes, it's working as intended. At each directory for which either the package mapping (package_config.json) or analysis options are specified, the analyzer looks for the pair of files that specify the whole analysis context and uses the information in those files when analyzing the code in that directory.

I agree that the message could be more helpful, and I like your suggestion.

@DanTup
Copy link
Member

DanTup commented Jun 9, 2021

Great - adding that seems to make it much more obvious what was going on with my repro:

Screenshot 2021-06-09 at 16 21 16

I'm not certain it's what Tim's hitting, but the message might at least help narrow it down next time it occurs.

dart-bot pushed a commit to dart-lang/sdk that referenced this issue Jun 9, 2021
May fix Dart-Code/Dart-Code#3259.

Change-Id: I4a81acd9186efacc90584c756fc9aef224378c65
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202964
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
@DanTup
Copy link
Member

DanTup commented Jun 9, 2021

@timsneath let me know if you see this again once you're using an SDK that includes dart-lang/sdk@6d763b4. The error message will hopefully be clearer.

My guess is that either it's something similar to the above (like a nested project), or you've somehow ended up with a path to the pedantic library in .packages/.dart_tool/package_config.json that's not valid (although the only way I can come up with for that to happen is manually nuking your pub-cache - something I do now and then but I don't know if you do!).

@timsneath
Copy link
Contributor Author

Aha! I've triggered it:
image

@bwilkerson
Copy link

Is there a runner/.dart_tool/package_config.json file? If so, does it specify a mapping to a version of package:lints that includes recommended.yaml?

@timsneath
Copy link
Contributor Author

There's a pubspec.lock and .packages folder that points to lint 1.2.0.

I should note in passing that I'm not sure how that runner folder got there (!)

@bwilkerson
Copy link

The image shows you including package:lints/recommended.yaml, not lint (note the lack of an s), and I'm guessing that the file runner/.packages doesn't have an entry for lints.

When analyzing files in runner, the analyzer uses both the file runner/.packages and the file analysis_options.yaml. The analysis options file contains a URI for package:lints, but the .packages file doesn't contain a mapping for that package, which is what caused the error.

@DanTup DanTup added the awaiting info Requires more information from the customer to progress label Jun 12, 2021
@timsneath
Copy link
Contributor Author

timsneath commented Jun 16, 2021 via email

@DanTup
Copy link
Member

DanTup commented Jun 28, 2021

@timsneath are you happy for me to close this as addressed by dart-lang/sdk@6d763b4 (including the folder in the error message), and if it comes up again and isn't explained by something like the above, we can re-open or file another issue?

@timsneath
Copy link
Contributor Author

Yeah, totally fine. The error message will now make it much easier to diagnose (modulo confusion over lint vs. lints).

@DanTup DanTup changed the title Can't find analysis_options.yaml in package:pedantic Error message when failing to resolve package:pedantic include in analysis_options.yaml is not descriptive enough Jun 28, 2021
@DanTup DanTup removed the awaiting info Requires more information from the customer to progress label Jun 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in editor Relates to code editing or language features in lsp/analysis server Something to be fixed in the Dart analysis server is bug
Projects
None yet
Development

No branches or pull requests

3 participants