Unhandled promise warning in typescript language server

Hi, and apologies if this is the wrong place for this, but I’ve been trying to setup the TypeScript LSP for a while and it seems to be throwing an error.

I’m running:
NVIM v0.5.0-dev+1123-g3fbff98cf
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

I created a very basic new index.ts file and a tsconfig.json in a new directory and it looks like the typescript lsp server is installed and attached properly from what I can tell.

None of the functions like :lua vim.lsp.buf.definition() seem to be having any effect. I’ve also enabled debugging and have added the log output below.

LSP Logs
[ INFO ] 2021-03-06T05:35:47-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:311 ]	"Starting RPC client"	{  args = { "--stdio" },  cmd = "typescript-language-server",  extra = {}}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] .../.mount_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp.lua:633 ]	"LSP[tsserver]"	"initialize_params"	{  capabilities = {    callHierarchy = {      dynamicRegistration = false,      <metatable> = <1>{        __tostring = <function 1>      }    },    textDocument = {      codeAction = {        codeActionLiteralSupport = {          codeActionKind = {            valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" },            <metatable> = <table 1>          },          <metatable> = <table 1>        },        dynamicRegistration = false,        <metatable> = <table 1>      },      completion = {        completionItem = {          commitCharactersSupport = false,          deprecatedSupport = false,          documentationFormat = { "markdown", "plaintext" },          preselectSupport = false,          snippetSupport = false,          <metatable> = <table 1>        },        completionItemKind = {          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 },          <metatable> = <table 1>        },        contextSupport = false,        dynamicRegistration = false,        <metatable> = <table 1>      },      declaration = {        linkSupport = true,        <metatable> = <table 1>      },      definition = {        linkSupport = true,        <metatable> = <table 1>      },      documentHighlight = {        dynamicRegistration = false,        <metatable> = <table 1>      },      documentSymbol = {        dynamicRegistration = false,        hierarchicalDocumentSymbolSupport = true,        symbolKind = {          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },          <metatable> = <table 1>        },        <metatable> = <table 1>      },      hover = {        contentFormat = { "markdown", "plaintext" },        dynamicRegistration = false,        <metatable> = <table 1>      },      implementation = {        linkSupport = true,        <metatable> = <table 1>      },      publishDiagnostics = {        relatedInformation = true,        tagSupport = {          valueSet = { 1, 2 },          <metatable> = <table 1>        },        <metatable> = <table 1>      },      references = {        dynamicRegistration = false,        <metatable> = <table 1>      },      rename = {        dynamicRegistration = false,        prepareSupport = true,        <metatable> = <table 1>      },      signatureHelp = {        dynamicRegistration = false,        signatureInformation = {          documentationFormat = { "markdown", "plaintext" },          <metatable> = <table 1>        },        <metatable> = <table 1>      },      synchronization = {        didSave = true,        dynamicRegistration = false,        willSave = false,        willSaveWaitUntil = false,        <metatable> = <table 1>      },      typeDefinition = {        linkSupport = true,        <metatable> = <table 1>      },      <metatable> = <table 1>    },    window = {      showDocument = {        support = false,        <metatable> = <table 1>      },      showMessage = {        messageActionItem = {          additionalPropertiesSupport = false,          <metatable> = <table 1>        },        <metatable> = <table 1>      },      workDoneProgress = true,      <metatable> = <table 1>    },    workspace = {      applyEdit = true,      configuration = true,      symbol = {        dynamicRegistration = false,        hierarchicalWorkspaceSymbolSupport = true,        symbolKind = {          valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },          <metatable> = <table 1>        },        <metatable> = <table 1>      },      workspaceFolders = true,      <metatable> = <table 1>    }  },  clientInfo = {    name = "Neovim",    version = "0.5.0"  },  initializationOptions = vim.empty_dict(),  processId = 30089,  rootPath = "/home/alex/Documents/lsp-test",  rootUri = "file:///home/alex/Documents/lsp-test",  trace = "off",  workspaceFolders = { {      name = "/home/alex/Documents/lsp-test",      uri = "file:///home/alex/Documents/lsp-test"    } }}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:391 ]	"rpc.send.payload"	{  id = 1,  jsonrpc = "2.0",  method = "initialize",  params = {    capabilities = {      callHierarchy = {        dynamicRegistration = false,        <metatable> = <1>{          __tostring = <function 1>        }      },      textDocument = {        codeAction = {          codeActionLiteralSupport = {            codeActionKind = {              valueSet = { "", "Empty", "QuickFix", "Refactor", "RefactorExtract", "RefactorInline", "RefactorRewrite", "Source", "SourceOrganizeImports", "quickfix", "refactor", "refactor.extract", "refactor.inline", "refactor.rewrite", "source", "source.organizeImports" },              <metatable> = <table 1>            },            <metatable> = <table 1>          },          dynamicRegistration = false,          <metatable> = <table 1>        },        completion = {          completionItem = {            commitCharactersSupport = false,            deprecatedSupport = false,            documentationFormat = { "markdown", "plaintext" },            preselectSupport = false,            snippetSupport = false,            <metatable> = <table 1>          },          completionItemKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 },            <metatable> = <table 1>          },          contextSupport = false,          dynamicRegistration = false,          <metatable> = <table 1>        },        declaration = {          linkSupport = true,          <metatable> = <table 1>        },        definition = {          linkSupport = true,          <metatable> = <table 1>        },        documentHighlight = {          dynamicRegistration = false,          <metatable> = <table 1>        },        documentSymbol = {          dynamicRegistration = false,          hierarchicalDocumentSymbolSupport = true,          symbolKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },            <metatable> = <table 1>          },          <metatable> = <table 1>        },        hover = {          contentFormat = { "markdown", "plaintext" },          dynamicRegistration = false,          <metatable> = <table 1>        },        implementation = {          linkSupport = true,          <metatable> = <table 1>        },        publishDiagnostics = {          relatedInformation = true,          tagSupport = {            valueSet = { 1, 2 },            <metatable> = <table 1>          },          <metatable> = <table 1>        },        references = {          dynamicRegistration = false,          <metatable> = <table 1>        },        rename = {          dynamicRegistration = false,          prepareSupport = true,          <metatable> = <table 1>        },        signatureHelp = {          dynamicRegistration = false,          signatureInformation = {            documentationFormat = { "markdown", "plaintext" },            <metatable> = <table 1>          },          <metatable> = <table 1>        },        synchronization = {          didSave = true,          dynamicRegistration = false,          willSave = false,          willSaveWaitUntil = false,          <metatable> = <table 1>        },        typeDefinition = {          linkSupport = true,          <metatable> = <table 1>        },        <metatable> = <table 1>      },      window = {        showDocument = {          support = false,          <metatable> = <table 1>        },        showMessage = {          messageActionItem = {            additionalPropertiesSupport = false,            <metatable> = <table 1>          },          <metatable> = <table 1>        },        workDoneProgress = true,        <metatable> = <table 1>      },      workspace = {        applyEdit = true,        configuration = true,        symbol = {          dynamicRegistration = false,          hierarchicalWorkspaceSymbolSupport = true,          symbolKind = {            valueSet = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26 },            <metatable> = <table 1>          },          <metatable> = <table 1>        },        workspaceFolders = true,        <metatable> = <table 1>      }    },    clientInfo = {      name = "Neovim",      version = "0.5.0"    },    initializationOptions = vim.empty_dict(),    processId = 30089,    rootPath = "/home/alex/Documents/lsp-test",    rootUri = "file:///home/alex/Documents/lsp-test",    trace = "off",    workspaceFolders = { {        name = "/home/alex/Documents/lsp-test",        uri = "file:///home/alex/Documents/lsp-test"      } }  }}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:492 ]	"decoded"	{  id = 1,  jsonrpc = "2.0",  result = {    capabilities = {      callsProvider = true,      codeActionProvider = true,      completionProvider = {        resolveProvider = true,        triggerCharacters = { ".", '"', "'", "/", "@", "<" }      },      definitionProvider = true,      documentFormattingProvider = true,      documentHighlightProvider = true,      documentRangeFormattingProvider = true,      documentSymbolProvider = true,      executeCommandProvider = {        commands = { "_typescript.applyWorkspaceEdit", "_typescript.applyCodeAction", "_typescript.applyRefactoring", "_typescript.organizeImports", "_typescript.applyRenameFile" }      },      foldingRangeProvider = true,      hoverProvider = true,      implementationProvider = true,      referencesProvider = true,      renameProvider = true,      signatureHelpProvider = {        triggerCharacters = { "(", ",", "<" }      },      textDocumentSync = 2,      typeDefinitionProvider = true,      workspaceSymbolProvider = true    }  }}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:391 ]	"rpc.send.payload"	{  jsonrpc = "2.0",  method = "initialized",  params = {    [true] = 6  }}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] .../.mount_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp.lua:660 ]	"LSP[tsserver]"	"server_capabilities"	{  callsProvider = true,  codeActionProvider = true,  completionProvider = {    resolveProvider = true,    triggerCharacters = { ".", '"', "'", "/", "@", "<" }  },  definitionProvider = true,  documentFormattingProvider = true,  documentHighlightProvider = true,  documentRangeFormattingProvider = true,  documentSymbolProvider = true,  executeCommandProvider = {    commands = { "_typescript.applyWorkspaceEdit", "_typescript.applyCodeAction", "_typescript.applyRefactoring", "_typescript.organizeImports", "_typescript.applyRenameFile" }  },  foldingRangeProvider = true,  hoverProvider = true,  implementationProvider = true,  referencesProvider = true,  renameProvider = true,  signatureHelpProvider = {    triggerCharacters = { "(", ",", "<" }  },  textDocumentSync = 2,  typeDefinitionProvider = true,  workspaceSymbolProvider = true}
    [ INFO ] 2021-03-06T05:35:47-0800 ] .../.mount_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp.lua:661 ]	"LSP[tsserver]"	"initialized"	{  resolved_capabilities = {    call_hierarchy = false,    code_action = true,    completion = true,    declaration = false,    document_formatting = true,    document_highlight = true,    document_range_formatting = true,    document_symbol = true,    execute_command = true,    find_references = true,    goto_definition = true,    hover = true,    implementation = true,    rename = true,    signature_help = true,    signature_help_trigger_characters = { "(", ",", "<" },    text_document_did_change = 2,    text_document_open_close = true,    text_document_save = true,    text_document_save_include_text = false,    text_document_will_save = false,    text_document_will_save_wait_until = false,    type_definition = true,    workspace_folder_properties = {      changeNotifications = false,      supported = false    },    workspace_symbol = true  }}
    [ DEBUG ] 2021-03-06T05:35:47-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:391 ]	"rpc.send.payload"	{  jsonrpc = "2.0",  method = "textDocument/didOpen",  params = {    textDocument = {      languageId = "typescript",      text = "const a = { z: 19 };\n\nconsole.log(a);\n",      uri = "file:///home/alex/Documents/lsp-test/index.ts",      version = 0    }  }}
    [ ERROR ] 2021-03-06T05:35:48-0800 ] ...unt_vimcskqip/usr/share/nvim/runtime/lua/vim/lsp/rpc.lua:458 ]	"rpc"	"typescript-language-server"	"stderr"	"(node:30097) UnhandledPromiseRejectionWarning: Error: write EPIPE\n    at afterWriteDispatched (internal/stream_base_commons.js:78:25)\n    at writeGeneric (internal/stream_base_commons.js:73:3)\n    at Socket._writeGeneric (net.js:714:5)\n    at Socket._write (net.js:726:8)\n    at doWrite (_stream_writable.js:415:12)\n    at writeOrBuffer (_stream_writable.js:399:5)\n    at Socket.Writable.write (_stream_writable.js:299:11)\n    at TspClient.sendMessage (/usr/local/lib/node_modules/typescript-language-server/lib/tsp-client.js:100:33)\n    at TspClient.request (/usr/local/lib/node_modules/typescript-language-server/lib/tsp-client.js:68:14)\n    at LspServer.<anonymous> (/usr/local/lib/node_modules/typescript-language-server/lib/lsp-server.js:195:45)\n(node:30097) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)\n(node:30097) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\n"

The last error is an internal tsserver error. Try setting your log level to trace. Also, make sure you’ve updated to the latest neovim, as I fixed a related issue a month or so ago.

And you are in the exact right place! Please use a more descriptive title in the future though. “Unhandled promise warning in typescript language server” for example!

Got it! I’ve edited the title.

I overrode the cmd for typescript to be cmd = {"typescript-language-server", "--stdio", --"--tsserver-log-file=/tmp/ts-logs.txt"} and it looks like it’s some kind of permissions issue.

From the error, it looks like it’s using the tsserver that is installed locally to the project, all of which is owned by the user. Is it some issue writing to stdio?

Error Log
Info 0    [18:14:46.196] Starting TS Server
Info 1    [18:14:46.197] Version: 3.8.3
Info 2    [18:14:46.197] Arguments: /snap/node/3786/bin/node /home/alex/test/node_modules/.bin/tsserver --logFile /tmp/ts-logs.txt --logVerbosity normal --cancellationPipeName /tmp/5c3764487be273069ff3eef75d33e5e2/tscancellation*
Info 3    [18:14:46.197] Platform: linux NodeVersion: 10 CaseSensitive: true
Err 4     [18:14:46.208] Exception on executing command unknown:

    EACCES: permission denied, read

    Error: EACCES: permission denied, read
Err 5     [18:14:46.224] Exception on executing command unknown:

    EACCES: permission denied, write

    Error: EACCES: permission denied, write
        at writeSync (fs.js:573:3)
        at SyncWriteStream._write (internal/fs/sync_write_stream.js:22:3)
        at doWrite (_stream_writable.js:415:12)
        at writeOrBuffer (_stream_writable.js:399:5)
        at SyncWriteStream.Writable.write (_stream_writable.js:299:11)
        at writeMessage (/home/alex/test/node_modules/typescript/lib/tsserver.js:147521:32)
        at Object.sys.write (/home/alex/test/node_modules/typescript/lib/tsserver.js:147624:43)
        at IOSession.Session.send (/home/alex/test/node_modules/typescript/lib/tsserver.js:144730:27)
        at IOSession.Session.event (/home/alex/test/node_modules/typescript/lib/tsserver.js:144733:22)
        at IOSession.event (/home/alex/test/node_modules/typescript/lib/tsserver.js:147327:44)
        at Immediate.<anonymous> (/home/alex/test/node_modules/typescript/lib/tsserver.js:147269:65)
        at runCallback (timers.js:705:18)
        at tryOnImmediate (timers.js:676:5)
        at processImmediate (timers.js:658:5)

I’m also able to run the ./node_modules/.bin/tsserver process locally and it doesn’t seem like it has any issues when I try and send it something like

{"seq":1,"type":"request","command":"open","arguments":{"file":"/home/alex/test/index.ts"}}

Does this mean the permissions error is because of typescript-language-server?

I also set up the lua lsp server and it seems to be working fine.

This is just a guess, but the EACCESS error may be a hint: The installation instructions for installing NodeJS via Snap recommend the --classic option to give full access to the filesystem. So I’d check this first, or even try installing NodeJS via a classic node version manager in your home directory.

3 Likes

Thanks! I removed node from snap and installed it with nvm and it seems to work now!

2 Likes