binding.pry not works(console input not available) if i start the server with bin/dev command. It only works with bin/rails s command.
I understand it has something to do with foreman and Procfile.dev, but I don't know how.
Is this a bug or is it supposed to be like this?
A popular approach is to use pry-remote which is useful in some ways I didn't expect: https://github.com/Mon-Ouie/pry-remote.
pry-remote opens a remote terminal, so where you drop your debugger line (binding.remote_pry in the case of pry-remote), you'll open another terminal and enter the debugging session by calling pry-remote in your shell.
I get this is a bit more complicated, I got used to it, and was able to get away from the noise logged by other process with Foreman.
I use rdbg + vscode remote debug and it works fine.
Update Procfile.dev like this to run rdbg with rails server and set a socket file
web: rdbg --command --nonstop --open=vscode --sock_path=tmp/sockets/rdbg.socket -- bundle exec bin/rails server
Install VSCode Ruby rdbg Debugger, configure launch.json like this
{
"version": "0.2.0",
"configurations": [
{
"name": "Attach to rdbg Process",
"type": "rdbg",
"request": "attach",
"debugPort": "${workspaceRoot}/tmp/sockets/rdbg.socket",
},
]
}
Now, VSCode will launching with debugger enable while you run bin/dev, or you can run debugger in vscode by F5 anytime
I launch a debug session through the Module option and specifying a folder, the app starts up and responds to requests - and code changes are seen when other services interact with mine by calling into it (print statements show the change in the terminal output of the IDE), however, breakpoints are not hit. How come?
My devcontainer.json file looks like this:
{
"name": "Existing Dockerfile",
"build": {
"dockerfile": "../Dockerfile",
"context": "../.",
"target": "deploy"
},
}
My Dockerfile does the usual stuff and runs our app with python -m app:
FROM python:3.9.3-slim AS deploy
COPIES SOME FILES
CMD ["python", "-m", "app"]
My problem was the version of python that was pulled in.
In my Dockerfile, I had to change:
FROM python:3.9.3-slim AS base
to
FROM python:3.9.4-slim AS base
Then breakpoints started working.
I am trying to set up debugging in VSCode and have run into a bit of a challenge. I typed the path to the localSourceRoot but Intellisense is telling me that it is deprecated and I should use pathMapping instead.
I am a newbie and don't know how to properly set that up. If someone could explain to me the variables and/or attributes pathMapping is requesting I would be forever in your debt.
My system info is as follows:
PHP version: 5.524
xdebug version: 2.2.5
OS Windows 8.1
Using Desktop Server version: 3.8.5
I checked the phpinfo() and it shows Xdebug in the file so I know that it is installed. The launch.json file is pretty basic with port 9000 and all of that. I just need to get that darned pathMapping thing done.
Thanks for any and all help.
I guess you're using the PHP debug extension ?
https://github.com/felixfbecker/vscode-php-debug
The README.md says the following:
Remote Host Debugging
To debug a running application on a remote host, you need to tell XDebug to connect to a different IP than localhost. This can either be done by setting xdebug.remote_host to your IP or by setting xdebug.remote_connect_back = 1 to make XDebug always connect back to the machine who did the web request. The latter is the only setting that supports multiple users debugging the same server and "just works" for web projects. Again, please see the XDebug documentation on the subject for more information.
To make VS Code map the files on the server to the right files on your local machine, you have to set the pathMappings settings in your launch.json. Example:
// server -> local
"pathMappings": {
"/var/www/html": "${workspaceRoot}/www",
"/app": "${workspaceRoot}/app"
}
Please also note that setting any of the CLI debugging options will not work with remote host debugging, because the script is always launched locally. If you want to debug a CLI script on a remote host, you need to launch it manually from the command line.
Thus is as much a reference to myself as well as others who might find this helpful. I am running VSCODE with xdebug and drupalvm and the following works for me after setting the following in php.ini
php_xdebug_idekey: VSCODE
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Listen for XDebug",
"type": "php",
"request": "launch",
"port": 9000,
"pathMappings": {
"/var/www/drupalvm/drupal": "${workspaceRoot}/drupal",
},
"log": true
},
{
"name": "Launch currently open script",
"type": "php",
"request": "launch",
"program": "${file}",
"cwd": "${fileDirname}",
"port": 9000
}
]
}
I am trying to debugg my angular code with vscode but doesnt work.
Cannot connect to the target: connect ECONNREFUSED 127.0.0.1:9222
I'm not sure you still need it, but I found the solution, since I was facing the same issue myself.
You must launch Chrome with remote debugging enabled in order for the extension to attach to it.
Windows
Right click the Chrome shortcut, and select properties
In the "target" field, append --remote-debugging-port=9222
Or in a command prompt, execute /chrome.exe --remote-debugging-port=9222
OS X
In a terminal, execute /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --remote-debugging-port=9222
Linux
In a terminal, launch google-chrome --remote-debugging-port=9222
I've found this info on the vs code chrome extension's github:
https://github.com/Microsoft/vscode-chrome-debug
Note - If you have already running instances of Chrome. Close them first before opening the updated Chrome window. Ref:- https://github.com/Microsoft/vscode-chrome-debug/issues/111
I got this error because I forgot to close the chrometabs from the previous time the application ran.
Just close those tabs and you are up and running again.
If you running this application in windows, and show you this message, try just restart your machine.
This works for me!
Add-on to the details added by digaomatias
Note: Stop already running Chrome instances/tabs before opening the updated Chrome window.
Reference from Github.
I was able to resolve this issue by stopping the debugger, closing all of my running Chrome windows, and then re-starting the debugger. Note that I'm using IIS Express.
To test and debug in vs code with angular and karma here is a solution,
angular test case to work you have to make a setting in 2 files,
1. Karm.conf.json ( this is a file that set your karma test runner.
2. LaunchSetting.json ( this is file used by your Chome Debugger extension in vs code)
So always first you have to run your karma test runner, on that port and then you can attach debugger on running port.
Step 1) Setup Karma.conf.json,
open default file created by cli,
you got something like this,
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
if you run ng test, you see in console you got some info like is Chrome is running, as well a page will open in browser with http://localhost:9876,
Now time to add headlesschrome with port 9222,
inside config.set, add this,
customLaunchers:{
ChromeHeadless:{
base:'Chrome',
flags:[
'--headless',
'--disable-gpu',
'--no-sandbox',
// Without a remote debugging port, Google Chrome exits immediately.
'--remote-debugging-port=9222',
]
}
}
and now go and add to the browser array ChoromeHeadless, so updated array will look like this, browsers: ['Chrome','ChromeHeadless'],
now run ng test you got in console chrome and chrome headless both running,
Step 2) Time to set up your launcher, to debug on 9222, debug to work you need sourcmap creation to work properly, that is important,
so for same to work just copy-paste config setting from below configuration array to your launchsetting.json configuration array as new config,
configurations: [
{
"name": "Attach to Chrome, with sourcemaps",
"type": "chrome",
"request": "attach",
"port": 9222,
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
"*": "${webRoot}/*",
},
"sourceMaps": true,
}
]
run ng test, and then go to debugger choose the config we add, your debugger working,
if you using npm run test, then make sure in your package.config where you define a run test, you have not set source map to false, if not then you can set debugger with,
npm run test as well.
Simply close the visual studio and open it again. It has solved my problem
I updated the Visual Studio Code to the latest version, the issue got resolved.
It's a issue about the debugger Browser. I solved it like this:
Install VS Code add in Microsoft Edge Tools for VS Code
Create a lauch config as:
{
"name": "Launch Microsoft Edge and open the Edge DevTools",
"request": "launch",
"type": "vscode-edge-devtools.debug",
"url": "https://localhost:3000/taskpane.html?_host_Info=Excel$Win32$16.01$en-US$$$$0",
"port": 9222,
}
Microsoft Edge Tools for VS Code
Then F5 start to debug.
Go to Tools => Options => Debug => General => and uncheck "Enable JavaScript debugging for Asp.Net (Chrome and IE)
Use like this:
{
"name": "Launch index.html",
"type": "chrome",
"request": "launch",
"file": "${workspaceRoot}/index.html",
"userDataDir": "${workspaceRoot}/out/chrome",
"runtimeExecutable": "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"
}
I was hoping to try VSCode on the AngularJS tutorial, say step 1, and get debugging and building working.
I was able to get it running, but it's a bit of a hack and VSCode doesn't like it.
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
// ONLY "node" and "mono" are supported, change "type" to switch.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app\\js\\app.js",
// Automatically stop program after launch.
"stopOnEntry": true,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": "run.bat",
// Environment variables passed to the program.
"env": { }
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858
}
]
}
I get an "Error Connection failed" even though it is actually running in a separate command prompt window.
Is there a way to for VSCode to debug a simple application like this that only uses package.json start like this:
"start": "http-server -a 0.0.0.0 -p 8000"
Thanks,
Derek
Visual Studio Code supports only Node and Mono debugging, it does not support debugging client JavaScript in the browser.
If you want debug Javascript in the browser, use the browser tools. If you want try out node.js debugging support in VSCode. Start with a sample node.js or express app, then follow the direction in Visual Studio Code website on setting up debugging.
If you would like to see Visual Studio Code supporting debugging, you can vote it up in user voice.