dotnet / vscode-csharp

Official C# support for Visual Studio Code
MIT License
2.86k stars 672 forks source link

Debugger silently drops errors logged by pipe program to stdout #1857

Closed marcfreiheit closed 6 years ago

marcfreiheit commented 6 years ago

Environment data

dotnet --info output:


Product Information:
 Version:            2.0.0
 Commit SHA-1 hash:  cdcd1928c9

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  10.12
 OS Platform: Darwin
 RID:         osx.10.12-x64
 Base Path:   /usr/local/share/dotnet/sdk/2.0.0/

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.0
  Build    : e8b8861ac7faf042c87a5c2f9f2d04c98b69f28d

VS Code version: Version 1.18.0 (1.18.0) C# Extension version: 1.13.0

Goal

I would like to create a .Net Core application based on multiple microservices. The services should be developed and published with Docker. The development process should be as comfortable as possible, without waiting minutes for Docker to build images and run the .Net app. Therefore, I'm mounting my source code inside the docker container and started the dotnet watch run -p /app command in order to restart the server on code changes. That's working well. Only downside is that I have to put my source code into a subfolder to not mount bin/ and obj/ folder, because the container is building the app and not my host machine. If you got improvements or ideas, please let me know! I'm still learning Docker and .Net Core, therefore I'm happy to get feedback!

Now I would like to debug my code inside the docker container.

Steps to reproduce

Dockerfile

FROM microsoft/dotnet:sdk

ENV ASPNETCORE_URLS http://*:5000
ENV ASPNETCORE_ENVIRONMENT Development
EXPOSE 5000
WORKDIR /app

# prereq
RUN apt-get update && \
    && rm -rf /var/lib/apt/lists/* \
    apt-get install -y--no-install-recommends unzip curl
# install vs debug to debug inside this container
RUN curl -sSL https://aka.ms/getvsdbgsh | bash /dev/stdin -v latest -l ~/vsdbg

# copy csproj and restore as distinct layers
COPY *.csproj .
RUN ["dotnet", "restore"]

ENTRYPOINT ["dotnet", "watch", "run", "-p /app"]

Compose

version: '3'

services:
  cablereelservice-db:
    image: postgres:latest
    environment:
      POSTGRES_USER: "cablereel"
      POSTGRES_PASSWORD: "secret"
    ports:
      - "6001:5432"
    volumes:
      - db-data-cablereel:/var/lib/postgresql/data

  cablereelservice:
    build:
      context: ./../../CargoSharp.Services.CableReel
      dockerfile: local.df
    ports:
      - "5001:5000"
    volumes:
      - ./../../CargoSharp.Services.CableReel/src:/app/src
    depends_on:
      - cablereelservice-db

volumes:
  db-data-cablereel:

launch.json

{
   "version": "0.2.0",
   "configurations": [
    {
        "name": "CableReelService (Attatch)",
        "type": "coreclr",
        "request": "attach",
        "processId": "${command:pickRemoteProcess}",
        "pipeTransport": {
            "pipeProgram": "docker",
            "pipeArgs": [ "exec", "-i", "local_cablereelservice_1" ],
            "debuggerPath": "~/vsdbg/vsdbg",
            "pipeCwd": "${workspaceRoot}",
            "quoteArgs": false
        },
        "sourceFileMap": {
            "/app/bin/Debug/netcoreapp2.0": "${workspaceRoot}/CargoSharp.Services.CableReel"
        }
    }
    ]
}

Project Strutcure

All microservices are hosted inside one repo. They should follow a structure similar the following one:

FirstMicroService
|
| _ bin/
| _ obj/
| _ src/
|      | _ models/
|      | _ services/
|      | _ modules/
|      | _ appsettings.json
|      | _ Startup.cs
|      | _ Program.cs
| _ .dockerignore
| _ FirstMicroService.csproj
| _ web.config

Expected behavior

  1. Start all containers
    docker-compose up
  2. Set a breakpoint and debug code of one specific container.

Actual behavior

Output:

Error: Starting: "docker" exec -i local_cablereelservice_1 ~/vsdbg/vsdbg --interpreter=vscode

and:

The pipe program 'docker' exited unexpectedly with code 126.

I have no clue what is going wrong and I don't get any valuable from the output and error message. I've tried selecting every process from the vs picker (${command:pickRemoteProcess}) without success. Any ideas or suggestions? Thanks in advance!

gregg-miskelly commented 6 years ago

@marcfreiheit What do you get when you run docker exec -i local_cablereelservice_1 ~/vsdbg/vsdbg --interpreter=vscode from a terminal?

marcfreiheit commented 6 years ago

Hey @gregg-miskelly, I'm getting this error: oci runtime error: exec failed: container_linux.go:265: starting container process caused "exec: \"/Users/marc/vsdbg/vsdbg\":stat /Users/marc/vsdbg/vsdbg: no such file or directory".

Fixed that by setting an absolute path in launch.json. Debugger starts and seems to trigger on breakpoints, but now I'm getting the following error: Unable to open 'HomeModule.cs': File not found (file:///app/src/modules/HomeModule.cs).

Btw, is there a way to enable debug or log messages in launch.json?

gregg-miskelly commented 6 years ago

Currently the pipe transport handler will do a good job of reporting errors logged to stderr, but if the pipe program logs errors of stdout we silently drop them on the floor. I will retitle this to investigate doing a better job here.

marcfreiheit commented 6 years ago

Great and thanks! When can I make use of the new debugging capabilities? (:

gregg-miskelly commented 6 years ago

We are aiming to release 1.14 pretty soon. But you can try it now if you like -- https://github.com/OmniSharp/omnisharp-vscode/wiki/Installing-Beta-Releases