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

Environment variables are not retrieved properly on Windows #7973

Closed
dschafhauser opened this issue Jun 5, 2020 · 0 comments
Closed

Environment variables are not retrieved properly on Windows #7973

dschafhauser opened this issue Jun 5, 2020 · 0 comments
Labels
bug bugs found in the application help wanted issues meant to be picked up, require help OS/Windows issues related to the Windows OS variable-resolver issues related to the variable-resolver extension

Comments

@dschafhauser
Copy link
Contributor

Bug Description:

Only environment variables which are entirely lowercase will be resolved properly by EnvVariablesServerImpl.

Steps to Reproduce:

  1. Set some environment variables like this:
setx UPPER_VAR UPPER_VAR_value
setx lower_var lower_var_value
  1. Create small example extension:
@inject(EnvVariablesServer)
private readonly envVariablesServer: EnvVariablesServer;

public example(): void {
	this.envVariablesServer
		.getValue("UPPER_VAR")
		.then((e: EnvVariable) =>
			console.log(`${e.name} = ${e.value}`)
		);
	
	this.envVariablesServer
		.getValue("lower_var")
		.then((e: EnvVariable) =>
			console.log(`${e.name} = ${e.value}`)
		);
}
  1. Executing yields the following output:
TypeError: Cannot read property 'name' of null
lower_var = lower_var_value

Possible fix

Lookup of variables on Windows is always lowercase:

async getValue(key: string): Promise<EnvVariable | undefined> {
if (isWindows) {
key = key.toLowerCase();
}
return this.envs[key];
}

However, the population of envs is with the actual names of the variables which might have arbitrary case:
constructor() {
const prEnv = process.env;
Object.keys(prEnv).forEach((key: string) => {
this.envs[key] = { 'name': key, 'value': prEnv[key] };
});
}

See discussion on Spectrum:
https://spectrum.chat/theia/general/how-to-resolve-environment-variables-in-a-launch-json-configuration~59464670-cb02-4b9d-8f05-084ffe96753f?m=MTU5MTM2NjIxODMwOA==

Additional Information

  • Operating System: Windows 10 (1809)
  • Theia Version: 1.1.0
@akosyakov akosyakov added bug bugs found in the application help wanted issues meant to be picked up, require help variable-resolver issues related to the variable-resolver extension OS/Windows issues related to the Windows OS labels Jun 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bugs found in the application help wanted issues meant to be picked up, require help OS/Windows issues related to the Windows OS variable-resolver issues related to the variable-resolver extension
Projects
None yet
Development

No branches or pull requests

2 participants