I'm debugging with Visual Studio Code Version 1.34.
I've setup a breakpoint that is not reached because of exceptions that are not critical.
How do I stop that behaviur? I'm coping the configuration file for debugging with Django in VSC.
launch.json
{
// 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": [
{
"type": "extensionHost",
"request": "launch",
"name": "Launch Extension",
"runtimeExecutable": "${execPath}",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}"
],
"outFiles": [
"${workspaceFolder}/out/**/*.js"
],
"preLaunchTask": "npm"
},
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
In python you can use a try and except
If you know the exception that is being thrown:
try:
with open('file.txt') as file:
read_data = file.read()
except FileNotFoundError as fnf_error:
print(fnf_error)
print('this will still be executed')
If you don't know what type of exception is thrown:
try:
function_that_throws()
except:
print('caught exception')
print('this is still executed')
Related
I have django-rest project on my vscode.The problem is that when I run the project in debug mode the breakpoints are not catched!!. I just get response without being stopped on that specific breakpoint.
This is my launch.json file
{
"version": "0.2.0",
"configurations": [
{
"name": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}\\manage.py",
"args": [
"runserver"
],
"django": true,
"justMyCode": true
}
]
}
BTW I send the requests by swagger!
I have also tried postman and got the same result!
(just got the response without the code being stopped on this view )
I send the requests to ManageUserView
[I'm getting this error][1]
Can't find Node.js binary "node": path does not exist. make sure not.js is installed and in your path or set the runtime executable in your launch.json
[my launch.json is ][2]
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": [
"<node_internals>/**"
],
"program": "${workspaceFolder}\\app.js"
}
]
}
What does the launch.json look like to run oclif project tests in debug mode? I can't seem to get it so that I set breakpoints and step in.
This launch.json config works for me:
{
"type": "node",
"request": "launch",
"name": "Mocha Tests",
"runtimeExecutable": "${workspaceFolder}/node_modules/ts-mocha/bin/ts-mocha",
"args": [
"${workspaceFolder}/test/**/*.ts"
],
"protocol": "inspector"
},
I benefitted from the response provided here:
https://github.com/oclif/oclif/issues/135#issuecomment-403622999
I've tested it with typescript, and program works great for debugging.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/bin/run",
"args": [
"--name",
"Callum",
"--force",
"argument"
]
}
]
}
I already setup a debugger for an existing django 1,11 project on vscode with the Microsoft python extension, but this will only works on http://127.0.0.1:5000/ (the homepage) I need this debugger to be hooked to my already running server on http://localhost:8000/
I need a setup that allows me to debug on vscode, make the code stop at specific breakpoints, debug code for various URLs using google chrome.
This is my launch.json
{
// 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": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
Python 2.7
Django 1.11
Visual Studio Code
MacOS Catalina
Please help.
Use 8000 as shown below in your setup
{
// 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": "Python: Django",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/manage.py",
"args": [
"runserver",
"8000",
"--noreload",
"--nothreading"
],
"django": true
}
]
}
On my Windows machine, I have Visual Studio Code installed. To run tests manually, I go in console to projects folder and enter
go test main_test.go
It works perfectly.
But I have a situation in which I need to debug my test to understand what's going on.
For this I open launch.json and add a configuration
{
"name": "Tests",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2346,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [
"main_test.go"
],
"showLog": true
}
After I press F5 I have
2017/03/29 13:28:11 server.go:73: Using API v1
2017/03/29 13:28:11 debugger.go:68: launching process with args: [./debug.test main_test.go main_go]
not an executable file
Process exiting with code: 1
Any ideas why this error occurs and what executable it's looking for?
To launch debugger for test I added one more configuration for launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "Code",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceRoot}",
"env": {},
"args": [],
"showLog": true
},
{
"name": "Test Current File",
"type": "go",
"request": "launch",
"mode": "test",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${file}",
"env": {},
"args": [],
"showLog": true
}
]
}
Also this configuration does not support tags. All tags in test files have to be disabled
// +build unit
...
For the mode, you can select auto which would choose either debug or test depending on active editor window.
All options for mode are auto, debug, test, exec, replay, core.
The resulting launch.json would look like:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch file",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${file}"
}
]
}
In my case it was not working because I named my file main_tests.go instead of main_test.go