Dart-code: LSP: Request textDocument/codeAction failed. Invalid file path

Created on 13 Jan 2021  Â·  19Comments  Â·  Source: Dart-Code/Dart-Code

Describe the bug
This just came up, have never seen it before. Whenever I type something in a specific dart file VSCode's Output panel opens up with an error message along with a notification about it. The message is as follows:

[Error - 20:39:21] Request textDocument/codeAction failed.
  Message: Invalid file path
  Code: -32003 
c:\Users\myuser\dev\project\lib\core\widgets\sidebar.dart

As I said, it only happens within this one specific file. No other files. It actually happens when clicking around in the file too. I've tried reloading the window, restarting VSCode, disabling and reenabling the Dart extension, disabling the Vim extension. Removing the file and recreating it pasting the stuff I previously had present in the file. Nothing works at this point. As I also said, this just started happening, and I have never seen it before. Nor do I have any idea on my own what I could have done to cause anything.

To Reproduce
I really don't know how to reproduce, to be honest...

Hmm... So while writing I started fiddling around a little bit. Started by removing everything in the file I had problems with and retyped it from a copy in Notepad. ~As soon as I came to adding the square brackets to this line~ I had actually typed out all the other stuff, since I used the tools present in VSCode to generate most of it:

static final List<String> _items = [];

It started freaking out. The type doesn't seem to matter. I think it's the combination of static, final, and the list square brackets OR curly braces, instead of square brackets. Also, the underscore does not matter, just so you know.

Also, to add for clarification: This works without errors:

static final String _string = "dwadnwaj";

// this too, although it doesn't compile of course
static final List<String> _grndjkgr = "adsnfshjfs";

The snippets above should be surrounded by the other content of the file in the steps below. Otherwise I cannot reproduce.

I'm gonna give my computer a restart a try. I'll report back if anything changes.

  1. Create a file from root flutter project, lib/core/widgets/sidebar.dart, with the following contents:
  2. Add the following contents to the file:

    import 'package:flutter/widgets.dart';
    
    /// This widget is a reimplementatino of the [Drawer] widget with the added
    ///  ability to act as a collapsable sidebar on desktop sized screens.
    class Sidebar extends StatelessWidget {
     static final List<Widget> _items = [
       _SidebarItem(),
     ];
    
     final bool expanded;
    
     const Sidebar({
       Key key,
       this.expanded = false,
     }) : super(key: key);
    
     @override
     Widget build(BuildContext context) {
       return LayoutBuilder(
         builder: (context, constraints) => ListView.builder(
           scrollDirection: Axis.vertical,
           itemCount: _items.length,
           itemBuilder: (context, index) => _items[index],
         ),
       );
     }
    }
    
    // class _SidebarItem {}
    

Sad truth is that I can't reproduce the narrowed problem in any other file. Just the sidebar.dart one.

I have a really hard time believing anyone else will be able to reproduce, it feels like it has to do something with my exact setup. But I guess we'll find out.

English is not my native language.

I'll be here for questions if anyone has them.

Thanks for everyone's time!

Expected behavior
No errors should be thrown.

Versions (please complete the following information):

  • VS Code version: 1.52.1 (user setup)
  • Dart extension version: v3.18.1 (LSP enabled)
  • Dart/Flutter SDK version: Dart 2.12.0 (build 2.12.0-133.2.beta) / Flutter 1.25.0-8.2.pre • channel beta
  • OS: Windows 10 2004 (since it might have to do with file paths?)
awaiting info stale

Most helpful comment

Probably someone has workarounds?
Have the same error

All 19 comments

Restarting my computer did not seem to fix the issue.

I'll keep investigating

Sorry for the delay! Could you try using the Capture Analysis Server Logs command to capture a log?

  • Run the Dart: Capture Analysis Logs command
  • Close and re-open the file that's having issues
  • Trigger the error
  • Click Cancel on the logging notification to stop logging and open the log file

Check the log file has nothing sensitive, then attach it here, share in a gist or email to me at [email protected].

Thanks!

No problem!

Here's the log file! Hope it helps!

Thanks!

Dart-Code-Log-2021-00-05 17-49-26.txt

I managed to hit this same error though with code I don't think matches yours, such as:

const dirHandle = await a.b();

I've filed an issue at https://github.com/dart-lang/sdk/issues/44699. Yours may be a different instance of the same sort of error, though I'm unable to reproduce with your code. I'll try again once that issue has been responded to and it's clearer why my sample code isn't analyzing correctly. Thanks!

Ok! Nice to hear that you can produce similar errors. Sounds good!

I get the same error - in only one file - but even when I just move the mouse - i.e. on hover.
Request textDocument/codeAction failed
Message: Invalid file path
Code: -32003

It started when I rebooted and restarted after the red error linting failed. I wqas getting weird false errors previously, and had to recreate the file, retyping (not copy-paste). That cleared the 'errors' to a clean file. Then after more coding, no errors show in problems pane, or in file, or in Explorer, but numerous errors show when trying to run the app.

I have restarted, uninstalled and reinstalled vscode, uninstalled and reinstalled the Dart extension, uninstalled and installed previous Dart extension. No change.

@DoctorVirginia are you able to share the exact contents of the (whole) file that seem to cause it? It could be similar to https://github.com/dart-lang/sdk/issues/44699, though if it's different code triggering it that would be useful to know. It could be some specific invalid syntax triggering it.

Thanks Danny, will post in the morning. I wouldn't be surprised if it is a syntax error as it is an early cut! V

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import '../utils/json_models.dart'; 
import '../utils/variables.dart';



Variables helper = Variables.instance;

class ResultsPanel extends StatefulWidget {
  ResultsPanel({Key key}) : super(key: key);

  @override
  _ResultsPanelState createState() => _ResultsPanelState();
}

class _ResultsPanelState extends State<ResultsPanel> {



  @override
  Widget build(BuildContext context) {
    return FutureBuilder<List<Head>>(
        // future: getHeadRecords(http.Client()),

        future: getHeadRecords(),
        builder: (context, snapshot) {
          if (snapshot.hasError) print(snapshot.error);

          return snapshot.hasData
              ? HeadList(heads: snapshot.data)
              : Center(child: CircularProgressIndicator());
        },
      ),
    );
  }
}

class HeadsList extends StatelessWidget {
  final List<Head> heads;

  HeadsList({Key key, this.heads}) : super(key: key);
  final List<Head> resultsList = doSearch() ;

  int splitCount=searchTerms.split(" ").length;
  List<Head> doSearch(){
    int splitCount = searchTerms.split(" ").length;
    // condition ? doThisIfTrue : doThisIfFalse
    //if one word, search in text only
    //if >1 word, search in phrases 
    print ('first $(heads[1].text');
    var idList = new list(); 
    for (var i = 0; i < heads.length; i++) {
      if (splitCount>1) {
        if (searchLang == "English"){
        //search phrases only
          if (heads[i].textGloss contains(searchTerms)) {

              idList.add(i);

          } else {
            //search words only
            if heads[i].gloss contains(searchTerms){
              idList.add(i);
            }else{
              if heads[i].textGloss contains(searchTerms){
                idList.add(i);
              }
            }
          }
        }else{
           if (heads[i].text contains(searchTerms)) {

              idList.add(i);

          } else {
            //search words only
            if heads[i].head contains(searchTerms){
              idList.add(i);
            }else{
              if heads[i].text contains(searchTerms){
                idList.add(i);
              }
            }
          }
        }
    }
  }

  @override
  Widget build(BuildContext context) {
    //some display
    return Container(
      margin: EdgeInsets.all(20),
      child: ListView(
          padding: EdgeInsets.only(top: 8, bottom: 8),
          scrollDirection: Axis.vertical,
          children: List.generate(idList.length, (index)) {
            var item = idList[index];
            return Card(
              color: Colors.white,
              child: Container(padding: EdgeInsets.all(16)
                     child: Text(item)),
            );
          })),
  }
}

@DoctorVirginia there are definitely some syntax errors in that file (for example if heads[i].head contains(searchTerms){) should have an open ( after the if), although I'm not seeing the errors you are, it seems to analyze fine and provide the errors.

Can you reproduce the issue in a small project you could share?

I have reverted to an earlier build with no problems, and slowly rebuilt the app. The error has reappeared after I have included the PWA client and an http request, and then try to compile with >flutter build web --no-sound-null-safety

I am getting this error on compilation:
Target dart2js failed: Exception: /C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/service_worker-0.2.4/lib/src/js_facade/isomorphic_fetch.dart:70:7:
Error: JS interop class 'Headers' conflicts with natively supported class 'Headers' in 'dart:html'.
class Headers implements HeadersInterface {
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/service_worker-0.2.4/lib/src/js_facade/isomorphic_fetch.dart:97:7:
Error: JS interop class 'Body' conflicts with natively supported class 'Body' in 'dart:html'.
class Body implements BodyInterface {
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/service_worker-0.2.4/lib/src/js_facade/isomorphic_fetch.dart:190:7:
Error: JS interop class 'Request' conflicts with natively supported class '_Request' in 'dart:html'.
class Request extends Body implements RequestInterface {
^
/C:/src/flutter/.pub-cache/hosted/pub.dartlang.org/service_worker-0.2.4/lib/src/js_facade/isomorphic_fetch.dart:270:7:
Error: JS interop class 'Response' conflicts with natively supported class '_Response' in 'dart:html'.
class Response extends Body implements ResponseInterface {
^
Error: Compilation failed.

And thereafter, the recurring error:
\src\flutter.pub-cache\hosted\pub.dartlang.org\service_worker-0.2.4\lib\src\js_facade\isomorphic_fetch.dart
[Error - 12:26:26 pm] Request textDocument/hover failed.
Message: Invalid file path
Code: -32003

Does this help?

Danny, my main problems now are the JS interop errors. I can't find anything to help? can you please advise or redirect me? Thanks, V

@DoctorVirginia are you able to share a sample project that triggers the error? On the surface it seems like build errors should be unrelated to the Invalid file path errors (which come from the analysis server), but I'd definitely like to get to the bottom of the analysis server error.

I'm afraid I don't know much about the JS interop, but if the errors are coming from source code in the service_worker package, I would file an issue in their GitHub to see if they can advise why it's not compiling.

Yes, all the issues are definitely caused by the PWA package - it calls service_worker-0.2.4, which calls isomorphic_fetch.dart which has the same js classes as (I believe) dart.html. When I remove only all references to the PWA package, all the problems disappear. Of course, this is a serious problem! I will post in the Dart SDK GitHub. Thanks, V.

If this seems to be triggering the "Invalid file path" errors too, I'd still be interested in a repro, as those errors are coming from the LSP server (which I contribute to). Whatever happens at compile time should not really be affecting the analysis server.

Hi Danny, didn't want to clutter up GitHub with all this: I'm very happy to
provide you with a repro, but it will take me some time to figure out how
to do that! I am working alone in a very remote part of Australia,
developing a PWA for an Indigenous language. I have struggled with GitHub
for years, but always worked alone, so I have never really seen any
advantage in it. Anyway, I will have another go, and try to get it up for
you. Cheers, Virginia

On Tue, Jan 26, 2021 at 7:45 PM Danny Tuppeny notifications@github.com
wrote:

If this seems to be triggering the "Invalid file path" errors too, I'd
still be interested in a repro, as those errors are coming from the LSP
server (which I contribute to). Whatever happens at compile time should not
really be affecting the analysis server.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/Dart-Code/Dart-Code/issues/3065#issuecomment-767489655,
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ANXSEOIWZKGYPNRFAJRSK4TS32TMNANCNFSM4WBL5J3A
.

--
Virginia Westwood

If it's easier, you can email me a zip file or something at [email protected], but please don't send anything sensitive - take a copy of the project and strip it down to the minimum you can that still reproduces the issue. Thanks!

Probably someone has workarounds?
Have the same error

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.

Was this page helpful?
0 / 5 - 0 ratings