Debugging from Visual Studio Code
Blockchain App Builder includes line-by-line debug support from Visual Studio Code for both TypeScript and Go projects.
On Microsoft Windows, configure Visual Studio Code to use Command Prompt as the default terminal instead of PowerShell. In the terminal menu in Visual Studio Code, click Select Default Profile, and then select Command Prompt.
Before you can debug your Go chaincode project, you must install the required Go tools in
Visual Studio Code. In Visual Studio Code, open the Command Palette and then run the
Go: Install/Update Tools
command. Install all of the Go
extensions that are listed.
Visual Studio Code uses Delve to debug Go. When you debug a Go chaincode for the first time, you will be prompted to install Delve. Accept the Delve installation before continuing. Visual Studio Code includes a built-in debugger for TypeScript.
- Open your chaincode project in Visual Studio Code Explorer. In the Chaincodes pane, right-click your chaincode and select Open in Explorer.
- Attach breakpoints to your code wherever necessary.
- Go to the Run menu and click Start Debugging. This attaches the debugger. It may take several seconds for the debugger to attach to the chaincode.
- Call any command from the Terminal which would execute your code.
If you've been using the Visual Studio Code interface to test your chaincode so far, you can follow the invocation syntax outlined in Test Your Chaincode on a Local Hyperledger Fabric Network.
The debugger will stop at your breakpoints. You can then start the debugging.
- Restart debugging to reflect new changes.
Because the chaincode is running in debug mode, the hot deployment of new changes does not happen automatically. You must manually restart the debugging process, using the debug controls in Visual Studio Code, in order to make the latest changes take effect.
Troubleshooting
dlv: failed to install dlv(github.com/go-delve/delve/cmd/dlv@latest): Error: Command failed:
C:\Program Files (x86)\Go\bin\go.exe get -x github.com/go-delve/delve/cmd/dlv@latest
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list
# get https://proxy.golang.org/github.com/@v/list
# get https://proxy.golang.org/github.com/go-delve/@v/list
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/@v/list
# get https://proxy.golang.org/github.com/go-delve/delve/@v/list
# get https://proxy.golang.org/github.com/@v/list: 410 Gone (0.420s)
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/@v/list: 410 Gone (1.040s)
# get https://proxy.golang.org/github.com/go-delve/@v/list: 410 Gone (1.062s)
# get https://proxy.golang.org/github.com/go-delve/delve/cmd/dlv/@v/list: 410 Gone (1.066s)
# get https://proxy.golang.org/github.com/go-delve/delve/@v/list: 200 OK (1.448s)
go: found github.com/go-delve/delve/cmd/dlv in github.com/go-delve/delve v1.8.3C:\Users\<UserName>\go\pkg\mod\github.com\go-delve\delve@v1.8.3\service\debugger\debugger.go:28:2:found packages native (proc.go) and
your_operating_system_and_architecture_combination_is_not_supported_by_delve(support_sentinel.go) in C:\Users\Asus\go\pkg\mod\github.com\go-delve\delve@v1.8.3\pkg\proc\native
There is no workaround for this error at this time.