Debug azure function 1.0 in vscode? - visual-studio-code

What is the proper way to use the azure function core tools and debug a V1 nodejs function locally using visual studio code?
For a new V2 function everything works great. I cannot update to V2 functions however. The build process is out of my control and attempting to do so broke the build.
The project started with:
"azure-functions-cli": "1.0.0-beta.94",
I couldn't get that to work and upgraded to:
"azure-functions-core-tools": "^1.0.20",
I cannot update to the latest 2.x version because I get errors. Initially:
Microsoft.Azure.WebJobs.Script: The host.json file is missing the required 'version' property. See https://aka.ms/functions-hostjson for steps to migrate the configuration file.
Trying just adding the version (either 1.0 or 2.0) didn't work.
So back to 1.0.20. I run it and I see this:
Debugger listening on [::]:5858
That's great because it matches my launch config:
{
"name": "Crazy attempt",
"type": "node",
"request": "attach",
"port": 5858,
},
Actually I can attach and it seems to work. My breakpoints look good, and changes to my code appear without restarting the function host. However, none of my breakpoints get hit. When I kill the function host the debugger quits in my vscode window. I know I have to be doing something wrong, but I don't know what it is...

I had to start with this:
func host start --debug VSCode

Related

Unable to debug Next.JS app (server side) in VSCode (following official debug guide, using official starter template)

I'm trying to debug the server-side code of a Next.JS app using VSCode's debugger, but I'm unable to get any breakpoints to bind. Debugging using chrome's dev tools (via chrome://inspect) to attach to the debugger behaves as expected.
Steps to reproduce:
Generate a Next.JS app using npx create-next-app#latest nextjs-blog --use-npm --example "https://github.com/vercel/next-learn/tree/master/basics/learn-starter" (as instructed at https://nextjs.org/learn/basics/create-nextjs-app/setup).
Create a launch.json as described in https://nextjs.org/docs/advanced-features/debugging#debugging-with-vs-code
Run the Next.js: debug server-side debug task in VSCode
Set a breakpoint in e.g. pages/index.js (I set mine on the return statement inside the Home component).
Visit the homepage
Expected behaviour:
VSCode binds the breakpoint (shows as red filled circle)
When loading the homepage, the breakpoint should be hit
Actual behaviour:
VSCode warns the breakpoint cannot be bound (see screenshot 1)
When loading the homepage, the breakpoint is not hit
Additional info:
I tried adding an "attach" entry in launch.json. Starting this after manually running npm run dev gave me a bit more info - VSCode gives more hints about what's going on - see screenshots 2 & 3. Here's the attach entry:
{
"name": "Attach",
"port": 9229,
"request": "attach",
"skipFiles": ["<node_internals>/**"],
"type": "node"
}
Am I missing some step or other? It's like the sourcemaps aren't working correctly or something?
System info
Next.JS version 13.1.6
VSCode version 1.75.0
Node version: 18.7.0
OS: Linux
Other questions
There are a couple other questions about debugging Next.JS server-side code with VSCode, but they're quite old now, and predate the official Next.JS documentation I follow in the steps to reproduce, so I'm not sure how relevant they are:
unable to debug Next.js app using visual code
debugging next.js with vscode debugger

vscode debugger does not launch debug console

I am so frustrated that my vscode debugger does not work on the remote servers suddenly today.
Here is the situation.
When I use the starred interpreter by vscode (the recommended one), it works smoothly. However, when I want to use other interpreters, the ones stored in personal folder on the server, the debugger doesn't launch a debug console and dose not enter the file.
Vscode can find and recognize the interpreters and I can use those interpreters to run scripts but can NOT DEBUG.(on the remote server) However, it works fine on my local machine with multiple python interpreter.
Can anyone give me some help? I have tried uninstall vscode completely on my end but still not work. Thank you so much!!
The Python extension debugger in VSCode requires a minimum Python version to run properly. However, this is not documented at all in the changelog at https://github.com/microsoft/vscode-python/releases, but you have to find out for yourself. For example, at the time of writing, version 2022.12.0 doesn't harmonize with Python 3.6.8.
As a workaround you have 2 options
Upgrade your interpreter to a newer version
Downgrade the Python extension to an older version
For the latter, go to the extensions page and under the Uninstall button you will find Install another version.... This makes it easy to try out what works best for you.
Just in case stumbles upon this question and the accepted answer doesn't work for you:
Try downgrading the Python extension version in VSCode. That fixed the issue for me. I picked a random version from ~2 months ago (when I wasn't having the issue). You might need to try a few versions though.
This workaround might work for you: use the interpreter that works for you but in the launch.json configuration file add a
"python": "/path/to/the/python/you/want",
I share the same experience. It seems that vscode fails to start the remote debugger with the interpreter I want but succeeds with the system interpreter.
For example:
"configurations": [
{
"name": "config_name",
"type": "python",
"python": "/path/to/desired/python",
"request": "launch",
"program": "/path/to/python/script.py",
"console": "integratedTerminal",
},
]

prevent VS code notification: 'launch' is already running. Do you want to start another instance?

I'm writing an ui with tkinter (ttk), and if I run the my program while an other instance of the ui is open, VS code (starting today) started giving a (error) notification which looks like this:
I'm not sure but I think this started happening when I started using ttk (instead of only tkinter).
I know you're not meant to run multiple instances of your program, but while coding it's very convenient to be able to see what you're changing along the way, and not have to close your previous instance.
Is there a way to stop this notification of appearing?
Is there a way to stop this notification of appearing?
VSCode 1.71 (August 2022) should offer an option for that.
See issue 147912 and PR 147914
Add new launch config debug option for silent '{0}' is already running. Do you want to start another instance? confirm dialog.
Tested with simple launch config:
{
"command": "npm start",
"name": "Run npm start",
"request": "launch",
"type": "node-terminal",
"suppressMultipleSessionWarning": true
}
This is available in VSCode Insiders today.
I bound F5 to restart, so i only have to run it once, and to see changes i restart that instance (changed run to F7)

VS Code opens a new debug console every time I build/run

Every time I build or run a program in VSCode a new python debug console is loaded. Before I know it I have 20+ and need to start deleting them. After 32 open consoles I get the error "The terminal process terminated with exit code: 256". I changed the terminal from the default console to git bash recently. How can I stop this?
A way around this issue is to stop VS Code from redundantly printing to the TERMINAL during debugging in the first place. Since it prints to the DEBUG CONSOLE as well, you can use that instead.
Change console to "none" "internalConsole" in each configuration in your project's launch.json file:
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
]
May 2019 Update: the "none" option was replaced by "internalConsole" so I edited my answer to reflect that. Here's the relevant GitHub Issue.
Adding "args": ["&&", "exit"], to launch.json remedies this for Git Bash. Certainly a hack, but I no longer have to manually close many debug terminals.
This may have been resolved in recent debug updates to core VS Code within the last year (as of 8/2022), but I was still seeing this intermittently.
I don't know if this will help the original poster, but I discovered that for me the issue persisted due to using Git Bash as the default terminal in Windows. Switching to Command Prompt as the default terminal fixed the issue. I haven't tested with other platforms or terminals.
Changing the default terminal to Command Prompt causes the Python extension to launch the "Python Debug" terminal with Command Prompt instead of Git Bash. I did log a VS Code/Python Extension defect about this. The initial response is that Git Bash is not officially supported currently.
There appears to be a communication problem between the Git Bash terminals and VS Code that causes this issue. Some of the characters between Git Bash and VS Code get dropped. Sometimes this mangles the debug command and I get and error and have to retry in addition to getting an extra debug window.
There is some additional background info and hacks to fix this from the past in this answer.
Hopefully fixed in the Insiders Build and should be in v1.54. See Debug opens a new integrated terminal for each Python session
. Test it in the Insiders Build if you can and report at the issue if it fixed/did not fix.
Actually you can delete all the instances of the terminal just by clicking on the trash can icon 🗑. If it does not work for the first time, restart the VS Code and try again.

Mock Debug: setting breakpoints in adapter

Learning how to set breakpoints in a debug adapter by using Mock Debug example on VSCode 1.14.0/Linux Mint 18. Following the demo instructions, I installed the Mock Debug extension and setting breakpoints on the "readme.md" worked fine. Then downloaded the .git source so I could step through the extensions.ts and mockDebug.ts. I set breakpoints in activate-"extensions.ts" and first line of each function-(mockDebug.ts). Ran the different launch types but none allowed me to hit any of the breakpoints.
Mock Debug extension has a launch.json with
{
"type": "mock",
"request": "launch",
"name": "Mock Debug",
"program": "${workspaceRoot}/readme.md",
"stopOnEntry": true
}
that does allow breakpoints in the readme.md file.
How do I set up the git source version to allow me to hit breakpoints in extensions.ts and mockDebug.ts? I can not seem to hit/stop on any breakpoints I have set.
Update: Tried using debugger; command as well
function activate(context) {
debugger;
...
}
I should have paid better attention to the docs. After a couple hours of sleep... the VSCode Team has excellent docs on extensions/example-debuggers:
In order to debug the debug adapter itself, we have to run it in
debug mode. This is most easily achieved by running the debug adapter
in 'server mode' and configure VS Code to connect to it.