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

[Windows] [coc.nvim] error: UnhandledRejection: Cannot read property 'reader' of undefined #1836

Closed
ohuu opened this issue Apr 30, 2020 · 6 comments

Comments

@ohuu
Copy link

ohuu commented Apr 30, 2020

Result from CocInfo

## versions
vim version: NVIM v0.4.3
node version: v13.12.0
coc.nvim version: 0.0.78-bcb2fe977c
term: vtpcon
platform: win32

Describe the bug

I'm using coc-metals and have raised this issue on the coc-metals repo but have been advised to report it here instead.

Installing coc-metals using :CocInstall works well but when it is preparing I receive this error:

[coc.nvim] error: UnhandledRejection: Cannot read property 'reader' of undefined
TypeError: Cannot read property 'reader' of undefined
    at C:\Users\Oliver\.nvim\plugged\coc.nvim\build\index.js:57558:48

Here are the relevant lines in index.js:

createConnection() {
    let errorHandler = (error, message, count) => {
        logger.error('connection error:', error, message);
        this.handleConnectionError(error, message, count);
    };
    let closeHandler = () => {
        this.handleConnectionClosed();
    };
    return this.createMessageTransports(this._clientOptions.stdioEncoding || 'utf8').then(transports => {
        return createConnection(transports.reader, transports.writer, errorHandler, closeHandler);
    });
}

The problem is that transports is undefined.

Reproduce the bug

On Windows 10 using Windows Terminal and Powershell 7 install coc-metals and open a scala file.

@chemzqm
Copy link
Member

chemzqm commented Apr 30, 2020

@ohuu
Copy link
Author

ohuu commented May 4, 2020

The problem is with a call to fs.existsSync. This call is made in order to see if the cmd exists. In coc-metals' case the cmd is java. The file exists but for some reason it returns false.

It may be related to this issue:
nodejs/node#17921

commenting out the existence check everything works fine so it's definitely this that's causing the problem.

@ohuu
Copy link
Author

ohuu commented May 7, 2020

It turns out that fs.existsSync is failing on Windows for 2 reasons:

  1. the path to cmd is in the Windows format (single \) e.g. C:\blah\blah\blah instead of C:/blah/blah/blah or C:\\blah\\blah\\blah
  2. The path does not contain the file's extension. In coc-metals' case it's looking for java instead of java.exe

@oblitum
Copy link
Member

oblitum commented May 7, 2020

The problem is with a call to fs.existsSync

Which call in the sources?

@chemzqm
Copy link
Member

chemzqm commented May 8, 2020

Should be

if (path.isAbsolute(cmd) && !fs.existsSync(cmd)) {

@chemzqm
Copy link
Member

chemzqm commented May 8, 2020

I've removed that check, it's not necessary.

@chemzqm chemzqm closed this as completed May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants