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

Failed to start debugger. Program could not be started. #13071

Closed
mkdirJava opened this issue Aug 4, 2024 · 7 comments
Closed

Failed to start debugger. Program could not be started. #13071

mkdirJava opened this issue Aug 4, 2024 · 7 comments
Labels
bug Something isn't working debugger Something to do with `bun --inspect` or the debugger vscode Something to do with the VSCode extension

Comments

@mkdirJava
Copy link

What version of Bun is running?

1.1.21

What platform is your computer?

Microsoft Windows NT 10.0.22631.0 x64

What steps can reproduce the bug?

Env Setup

Visual Studio Code ( Version: 1.92.0 )
Bun for Visual Studio Code Extension, Oven ( Version: v0.0.12, extension Id oven.bun-vscode)
Code found in
https://github.com/mkdirJava/BunIssueReplication

Steps

Clone the above repo
Open in Vscode
Whilst main panel has index.ts open run Vscode debug "Debug File"
Open "Debug Console" in the bottom panel ( might have to open a terminal and find the tab )
"Debug Console" reports
"Failed to start debugger.
Program must be a JavaScript or TypeScript file."

Looked further into the issue via logs found in
C:\Users<user>\AppData\Roaming\Code\logs\20240804T094251\window1\exthost\exthost.log

Looks like the extension is trying to open a reserved port

2024-08-04 09:46:15.465 [error] Error: listen EACCES: permission denied C:\Users<user>\AppData\Local\Temp\0vyubmzqvx4g.sock
at Server.setupListenHandle [as _listen2] (node:net:1881:21)

image

What is the expected behavior?

Given I have the repo cloned
https://github.com/mkdirJava/BunIssueReplication
And the Bun Extension installed
When I have the index.ts file open
And I have a break point set
And I click debug in Vscode
Then I should hit the debug line in debug mode

What do you see instead?

Failed to start debugger.
Program must be a JavaScript or TypeScript file.

Additional information

Looked further into the issue via logs found in
C:\Users<user>\AppData\Roaming\Code\logs\20240804T094251\window1\exthost\exthost.log

Looks like the extension is trying to open a reserved port

2024-08-04 09:46:15.465 [error] Error: listen EACCES: permission denied C:\Users<user>\AppData\Local\Temp\0vyubmzqvx4g.sock

@liudonghua123
Copy link
Contributor

I got the similar logs in %appdata%\Code\logs\20240805T003523\window2\exthost\exthost.log

2024-08-05 00:37:56.722 [error] Error: listen EACCES: permission denied C:\Users\LIUD~1.H\AppData\Local\Temp\vd7f7p7ez1r.sock
    at Server.setupListenHandle [as _listen2] (node:net:1881:21)
    at listenInCluster (node:net:1946:12)
    at Server.listen (node:net:2061:5)
    at new UnixSignal (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\signal.ts:40:18)
    at DebugAdapter.#launch (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:493:20)
    at DebugAdapter.launch (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:439:18)
    at DebugAdapter.Adapter.request (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:350:21)
    at DebugAdapter.emit (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:297:26)
    at FileDebugSession.handleMessage (c:\Users\Liu.D.H\.vscode\extensions\oven.bun-vscode-0.0.12\src\features\debug.ts:195:20)
    at D.sendMessage (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:163:706)
    at s.$sendDAMessage (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:162:12040)
    at E.S (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:5980)
    at E.Q (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:5746)
    at E.M (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:4778)
    at E.L (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:3605)
    at i.value (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:2297)
    at n.B (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:737)
    at n.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:954)
    at s.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:97:14453)
    at i.value (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:177:8655)
    at n.B (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:737)
    at n.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:954)
    at s.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:97:14453)
    at MessagePortMain.<anonymous> (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:177:6781)
    at MessagePortMain.emit (node:events:519:28)
    at MessagePortMain.emit (node:domain:488:12)
    at Object.MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2285)

@mkdirJava
Copy link
Author

mkdirJava commented Aug 4, 2024

I have done a little more "digging".
I've read through stackoverflow and these tickets.
The readings suggest to add in the location of the bun binary in the configuration

I still get this error in the logs

2024-08-04 17:57:39.466 [error] Error: listen EACCES: permission denied C:\Users\proje\AppData\Local\Temp\zkwvm6dkiif.sock
at Server.setupListenHandle [as _listen2] (node:net:1881:21)
image

however in the debug console I see

Failed to start inspector:
40 | }
41 | },
42 | close: () => {
43 | writer.close(), pendingMessages.length = 0;
44 | }
45 | }, parseUrl = function(input) {
^
TypeError: "ws+unix://C:\Users<user>\AppData\Local\Temp\fhyuenpoufo.sock?wait=1" cannot be parsed as a URL.
at internal:debugger:45:23
at new Debugger (internal:debugger:124:14)
at internal:debugger:100:13

So it looks like VsCode Bun extenstion is not recognizing it is working on a windows machine and is instead treating the windows path as a unix path


Then I used WSL2 (Ubuntu) and followed the same steps

  1. In Vscode, open wsl2
  2. Put a debugger on
  3. Open Bun extenstion and update the location of the Bun binary
  4. Use the same code and start a debugger
  5. Run the debugger
  6. IT WORKS !!!!

image

So I have a thought of:

The VSCode Bun Extension has an issue in Windows:

  • Cannot treat certain file as sockets due to permissions

  • The debug ws path is not sensitive to the windows platform

  • There is an odd behavior to specify the location of the Bun binary . The extension mentions it will take bun from the path. I am unsure it does given the above findings

@liudonghua123
Copy link
Contributor

liudonghua123 commented Aug 5, 2024

I have also noticed some error logs in DEBUG CONSOLE. It's clear the error is related TypeError: "ws+unix://C:\Users\LIUD~1.H\AppData\Local\Temp\gi63g4zfvt4.sock?wait=1" cannot be parsed as a URL..

It's really strange, I only got Failed to start debugger\nProgram must be a JavaScript or Typescript file. a few days ago.

Failed to start inspector:
 40 |       }
41 |     },
42 |     close: () => {
43 |       writer.close(), pendingMessages.length = 0;
44 |     }
45 | }, parseUrl = function(input) {
                           ^
TypeError: "ws+unix://C:\Users\LIUD~1.H\AppData\Local\Temp\gi63g4zfvt4.sock?wait=1" cannot be parsed as a URL.
      at internal:debugger:45:23
      at new Debugger (internal:debugger:124:14)
      at internal:debugger:100:13

And the following error log in exthost.log.

2024-08-05 09:08:55.662 [error] Error: listen EACCES: permission denied C:\Users\LIUD~1.H\AppData\Local\Temp\x55hpvs12h.sock
    at Server.setupListenHandle [as _listen2] (node:net:1855:21)
    at listenInCluster (node:net:1920:12)
    at Server.listen (node:net:2019:5)
    at new UnixSignal (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\signal.ts:40:18)
    at DebugAdapter.#launch (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:493:20)
    at DebugAdapter.launch (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:439:18)
    at DebugAdapter.Adapter.request (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:350:21)
    at DebugAdapter.emit (c:\Users\Liu.D.H\.vscode\extensions\bun-debug-adapter-protocol\src\debugger\adapter.ts:297:26)
    at FileDebugSession.handleMessage (c:\Users\Liu.D.H\.vscode\extensions\oven.bun-vscode-0.0.12\src\features\debug.ts:195:20)
    at D.sendMessage (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:163:706)
    at o.$sendDAMessage (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:162:12042)
    at S (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:5986)
    at S.Q (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:5752)
    at S.M (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:4778)
    at S.L (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:3605)
    at n.value (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:151:2297)
    at r.B (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:737)
    at r.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:954)
    at o.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:108:14502)
    at n.value (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:177:8639)
    at r.B (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:737)
    at r.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:83:954)
    at o.fire (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:108:14502)
    at MessagePortMain.<anonymous> (c:\Users\Liu.D.H\AppData\Local\Programs\Microsoft VS Code\resources\app\out\vs\workbench\api\node\extensionHostProcess.js:177:6765)
    at MessagePortMain.emit (node:events:514:28)
    at MessagePortMain.emit (node:domain:488:12)
    at Object.MessagePortMain._internalPort.emit (node:electron/js2c/utility_init:2:2285)

From the error log and the code of vscode extension, it seems the following code doesn't working on windows.

const url = `ws+unix://${randomUnixPath()}`;
const signal = new UnixSignal();

this.#url = parseUrl(url);
this.#createBackend = (refEventLoop, receive) => {

I also evaluated new URL('ws+unix://C:\\Users\\LIUD~1.H\\AppData\\Local\\Temp\\2kic29xeo85.sock?wait=1') in Browser Devtools, node and bun. It seems only devtools parsed the js expression without errors.

image

And If I changed \\ to /, all of them parsed without errors.

image

@liudonghua123
Copy link
Contributor

Well, after some debugging, I found the problem is related to unix option in Bun.serve on windows only support path that can not prefixed with a leading /. And the pathname of debug url parsed to the internal/debugger will auto prefixed with a leading /.

function parseUrl(input: string): URL {
if (input.startsWith("ws://") || input.startsWith("ws+unix://") || input.startsWith("unix://")) {
return new URL(input);
}

#listen(): void {
const { protocol, hostname, port, pathname } = this.#url;
if (protocol === "ws:" || protocol === "ws+tcp:") {
const server = Bun.serve({
hostname,
port,
fetch: this.#fetch.bind(this),
websocket: this.#websocket,
});
this.#url.hostname = server.hostname;
this.#url.port = `${server.port}`;
return;
}
if (protocol === "ws+unix:") {
Bun.serve({
unix: pathname,
fetch: this.#fetch.bind(this),
websocket: this.#websocket,
});
return;
}

For the sample code.

import { pathToFileURL } from 'url';

Bun.serve({
  unix: 'D:/echo.sock', // works, pathToFileURL('D:/echo.sock').pathname or '/D:/echo.sock' failed with EUNKNOWN: An unknown error occurred
  fetch(req) {
    return new Response(`404!`);
  },
});

So the fix maybe update unix option in Bun.serve to support a optional leading prefix / on windows to keep compatible.

@mkdirJava
Copy link
Author

raised a PR, but need to add in tests
#13099

@LeulAria
Copy link

LeulAria commented Aug 18, 2024

getting this on mac aswell...

@RiskyMH RiskyMH added debugger Something to do with `bun --inspect` or the debugger vscode Something to do with the VSCode extension and removed needs triage labels Jan 30, 2025
@RiskyMH
Copy link
Member

RiskyMH commented Jan 30, 2025

This should be fixed by @snoglobe in #14048!

@RiskyMH RiskyMH closed this as completed Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working debugger Something to do with `bun --inspect` or the debugger vscode Something to do with the VSCode extension
Projects
None yet
Development

No branches or pull requests

4 participants