Skip to content
This repository has been archived by the owner on Jul 16, 2021. It is now read-only.

Error when using configuration (The "file" argument must be of type string) #2

Open
hcs42 opened this issue Dec 30, 2019 · 1 comment

Comments

@hcs42
Copy link

hcs42 commented Dec 30, 2019

The error

When I open an Erlang file, I get the following error:

[coc.nvim] error:     at Object.<anonymous> (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc-erlang_ls/lib/index.js:156:20)

:CocInfo shows the following error:

## versions

vim version: VIM - Vi IMproved 8.1 (2018 May 18, compiled Sep 25 2018 13:59:45)
node version: v13.5.0
coc.nvim version: 0.0.74-cd348f4905
term: dumb
platform: linux

## Messages
Messages maintainer: Bram Moolenaar <[email protected]>
[coc.nvim] error: UnhandledRejection: The "file" argument must be of type string. Received type object
[coc.nvim] error: TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
[coc.nvim] error:     at validateString (internal/validators.js:118:11)
[coc.nvim] error:     at normalizeSpawnArguments (child_process.js:405:3)
[coc.nvim] error:     at spawn (child_process.js:545:13)
[coc.nvim] error:     at Object.execFile (child_process.js:231:17)
[coc.nvim] error:     at /home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc-erlang_ls/lib/index.js:102:25
[coc.nvim] error:     at LanguageClient.createMessageTransports (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:54119:48)
[coc.nvim] error:     at LanguageClient.createConnection (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56580:21)
[coc.nvim] error:     at LanguageClient.resolveConnection (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56362:44)
[coc.nvim] error:     at LanguageClient.start (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56299:14)
[coc.nvim] error:     at Object.<anonymous> (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc-erlang_ls/lib/index.js:154:20)
## Output channel: coc-erlang


## Output channel: erlang_ls

[Error  - 9:30:35 PM] Starting client failed:
TypeError [ERR_INVALID_ARG_TYPE]: The "file" argument must be of type string. Received type object
    at validateString (internal/validators.js:118:11)
    at normalizeSpawnArguments (child_process.js:405:3)
    at spawn (child_process.js:545:13)
    at Object.execFile (child_process.js:231:17)
    at /home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc-erlang_ls/lib/index.js:102:25
    at LanguageClient.createMessageTransports (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:54119:48)
    at LanguageClient.createConnection (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56580:21)
    at LanguageClient.resolveConnection (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56362:44)
    at LanguageClient.start (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc.nvim/build/index.js:56299:14)
    at Object.<anonymous> (/home/hcs/d/cp/vim/vimfiles/pack/dixon-plugins/opt/coc-erlang_ls/lib/index.js:154:20)

The possible reason

Here is my configuration:

{
        "erlang_ls.erlang_ls_path": {
          "type": "string",
          "default": "/home/hcs/w/els/erlang_ls/_build/default/bin/erlang_ls",
          "description": "path of erlang_ls"
        },
        "erlang_ls.port": {
          "type": "number",
          "default": 19527,
          "description": "Port to communicate with language server."
        },
        "erlang_ls.trace.server": {
          "type": "string",
          "default": "off",
          "enum": [
            "off",
            "messages",
            "verbose"
          ],
          "description": "Trace level of vim language server"
        }
}

If I put the following debug printout lines into coc-erlang_ls/lib/index.js (ts source):

 function startServer(serverPath, serverPort) {
     return function () {
+        logger.appendLine('serverPath=');
+        logger.appendLine(JSON.stringify(serverPath));
         child_process_1.execFile(serverPath, [serverPort.toString()]);

then it shows that serverPath is an object (not a string):

serverPath=
{"type":"string","default":"/home/hcs/w/els/erlang_ls/_build/default/bin/erlang_ls","description":"path of erlang_ls"}

The problem is that the code that eventually tries to use the serverPath variable expects a string (not an object).

If I modify the configuration file to have a string instead of an object (not only for erlang_ls_path but also for port):

{
        "erlang_ls.erlang_ls_path": "/home/hcs/w/els/erlang_ls/_build/default/bin/erlang_ls",
        "erlang_ls.port": 19527,
        "erlang_ls.trace.server": {
          "type": "string",
          "default": "off",
          "enum": [
            "off",
            "messages",
            "verbose"
          ],
          "description": "Trace level of vim language server"
        }
}

then coc-erlang_ls can start erlang_ls as expected and the problem goes away.

The question is: why? Any ideas about why configuration is apparently read differently on my machine?

This is the line that reads the configuration, but I didn't get deeper into what kind of magic is done by this WorkspaceConfiguration object.

@hyhugh
Copy link
Owner

hyhugh commented Jan 19, 2020

Sorry for my late reply, i just got back from holiday.
I think the problem was because of my confusing README file.
In your coc config file, the type of each config variable should be the type field of the config variable declarations in the package.json. That's my bad, i'll fix the readme very soon.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants