tamasfe / taplo

A TOML toolkit written in Rust
https://taplo.tamasfe.dev
MIT License
1.38k stars 113 forks source link

download of https://www.schemastore.org/api/json/catalog.json fails behind proxy #319

Open j-hap opened 2 years ago

j-hap commented 2 years ago

when behind a company proxy, the vs code extension fails to download the schema catalog

 WARN update_configuration:initialize: failed to fetch catalog error=error sending request: JsValue(KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
    at ClientRequest.<anonymous> (c:\Users\j-hap\.vscode\extensions\tamasfe.even-better-toml-0.18.1\dist\server.js:12:15885)
    at ClientRequest.emit (node:events:526:28)
    at TLSSocket.socketErrorListener (node:_http_client:442:9)
    at TLSSocket.emit (node:events:526:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21))

Caused by:
    JsValue(KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
    KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
        at ClientRequest.<anonymous> (c:\Users\j-hap\.vscode\extensions\tamasfe.even-better-toml-0.18.1\dist\server.js:12:15885)
        at ClientRequest.emit (node:events:526:28)
        at TLSSocket.socketErrorListener (node:_http_client:442:9)
        at TLSSocket.emit (node:events:526:28)
        at emitErrorNT (node:internal/streams/destroy:157:8)
        at emitErrorCloseNT (node:internal/streams/destroy:122:3)
        at process.processTicksAndRejections (node:internal/process/task_queues:83:21)) self.root=root:///
ERROR update_configuration:initialize: failed to add schemas from catalog error=error sending request: JsValue(KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
KA: request to https://www.schemastore.org/api/json/catalog.json failed, reason: connect ETIMEDOUT 20.42.128.105:443
    at ClientRequest.<anonymous> (c:\Users\j-hap\.vscode\extensions\tamasfe.even-better-toml-0.18.1\dist\server.js:12:15885)
    at ClientRequest.emit (node:events:526:28)
    at TLSSocket.socketErrorListener (node:_http_client:442:9)
    at TLSSocket.emit (node:events:526:28)
    at emitErrorNT (node:internal/streams/destroy:157:8)
    at emitErrorCloseNT (node:internal/streams/destroy:122:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:83:21)) self.root=root:///

It succeeds when I'm not using the proxy to connect to the internet. I have the http.proxy set in vs code, my powershell profile as well as the environment variables HTTP_PROXY and HTTPS_PROXY, but to no avail.

I saw that one can disable schemas in the settings to skip the time to wait for the request to fail, but it would be nice if the extension would use the proxy defined in the vscode settings to fetch schemas.

Thank you for the extension!

tamasfe commented 2 years ago

This should hopefully be just reqwest's proxy. If I'm correct it works as-is with compiled executables, but since environment variables are not available in WASM, reqwest is not aware of them.

We just manually need to check for these env vars, or in the worst case patch node-fetch to use a proxy in the extension.

tamasfe commented 1 year ago

Manually passing the env var seems to be enough for reqwest, this should be fixed in the next version.

tamasfe commented 1 year ago

Reopening, as it's apparently not this easy under WASM.

tresuke commented 10 months ago

Any progress on this issue? Hopefully this issue will be resolved.

0f-0b commented 1 month ago

Here's a workaround.

  1. Run the command “Extensions: Open Extensions Folder”.
  2. Open the subfolder named tamasfe.even-better-toml-0.19.2.
  3. Run npm i --no-save undici in this folder.
  4. Append these two lines to dist/server.js. Replace your.proxy with the address of your proxy. Also refer to the undici docs if your proxy requires authentication.
const { ProxyAgent, setGlobalDispatcher } = require("undici");
setGlobalDispatcher(new ProxyAgent("http://your.proxy"));
  1. Restart the extension host.

This only works for VS Code versions since late 2023, because these versions ship with undici's fetch, and the extension won't use node-fetch in case there is already a built-in one.

tresuke commented 1 month ago

@0f-0b I got it working fine with that workaround😄 Thank you, very much! In addition, in the case of WSL or remote SSH connection, it seemed to work if I did the same thing under the .vscode-server directory of the remote destination.