Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of environmental variables for setting port in launch.json for Node debugging #192014

Closed
RobertBarachini opened this issue Sep 1, 2023 · 6 comments · Fixed by microsoft/vscode-js-debug#1880
Assignees
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Milestone

Comments

@RobertBarachini
Copy link

When trying to debug multiple (Node + Docker) services at the same time, I've started using environment variables for a more flexible setup when creating a complete dev environment which is not bound to a hard-coded config (example: hostname+port, as defined in launch.json).

Similar to https://github.com/microsoft/vscode-python/issues/18841 and https://github.com/microsoft/vscode-java-debug/issues/962 I'd like to use environment variables to set "port" and "hostname". Using environment variables to set different values within the launch.json configuration would be extremely useful for creating dynamic configs for developers on the team (this would allow us to change some parts of our dev environment without having to change tracked code - in this case launch.json; the same variable is also used within docker-compose.yml when defining a forwarded debug port) - even a way to turn off (or override) validation for types within launch.json (in general, not just for this Node configuration) would help a lot.

Example configuration:

{
	"version": "0.2.0",
	"configurations": [
		{
			"name": "Attach to Docker port",
			"type": "node",
			"request": "attach",
			// "port": 9230,
			"port": "${env:PORT_SOME_SERVICE_DEBUG}",
			//"address": "localhost"
			"address": "${env:ADDRESS_SOME_SERVICE}",
			"localRoot": "${workspaceFolder}",
			"remoteRoot": "/usr/src/app",
			"restart": true,
			"sourceMaps": true,
			"skipFiles": [
				"<node_internals>/**"
			]
		}
	]
}

gives the following validation error: Incorrect type. Expected "number". even though the evaluated variable is a number.

Allowing the use of environmental variables (or even allowing numbers as string) for setting port would help a lot.

@roblourens
Copy link
Member

I assume that the environment variable is resolved, but js-debug could parse a number from a string?

@RobertBarachini
Copy link
Author

The message Incorrect type. Expected "number". comes up under "Warnings" in "PROBLEMS" panel (and is underlined in the editor accordingly). Not sure if the variable is being evaluated for the "port" key at all (or how it works under the hood), however it can be resolved under other references which support the "env" syntax. End result is debugger not being attached to the running Docker process - I assumed it automatically reverts to the default port number (9229), however the little debug controls window still pops up without actually being attached to anything.

@connor4312 connor4312 added feature-request Request for new features or functionality debug Debug viewlet, configurations, breakpoints, adapter issues labels Nov 2, 2023
@connor4312 connor4312 added this to the November 2023 milestone Nov 2, 2023
connor4312 added a commit to microsoft/vscode-js-debug that referenced this issue Nov 2, 2023
@HelmerBarcos

This comment was marked as off-topic.

@connor4312 connor4312 added the verification-needed Verification of issue is requested label Nov 27, 2023
@roblourens
Copy link
Member

This is the case it's supposed to handle, right? Getting this warning but I see you updated the schema

image

@connor4312
Copy link
Member

Are you on js-debug-nightly? js-debug stable is only bumped in the next Insiders

image

@rzhao271 rzhao271 added the verified Verification succeeded label Nov 29, 2023
@roblourens
Copy link
Member

Oh I think I need to not just have nightly installed but also disable the builtin one. Now I see the right thing.

I do that then from time to time I end up reenabling the stable one for whatever reason

@github-actions github-actions bot locked and limited conversation to collaborators Dec 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
debug Debug viewlet, configurations, breakpoints, adapter issues feature-request Request for new features or functionality verification-needed Verification of issue is requested verified Verification succeeded
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants