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

Fix exception import Az.Accounts caused by env var #18312

Conversation

isra-fel
Copy link
Member

@isra-fel isra-fel commented May 26, 2022

Description

Fix #18304

As stated in the issue, on non-Windows OS, it is possible to have multiple environment variables which only differ by case.
The original code didn't take this into consideration when listing all the environment variables and putting them in a case-insensitive dictionary using IEnumerable.ToDictionary() which throws an exception in the above scenario because of duplicated dictionary keys.

The solution is to write the logic of converting IEnumerable to Dictionary manually and overwrite previous value when keys are the same.

I'm thinking, to make config framework more robust against unexpected errors, we can do something like this:

// in AzureSessionInitializer.cs
try
{
    configInitializer.Initiaize();
}
catch (e)
{
    WriteWarning(e);
    configInitializer.InitilzeInSafeMode(); // initialize config framework without config providers (json, env var, in-memory). Only default values are available.
}

I will cover this in another PR.

Checklist

  • I have read the Submitting Changes section of CONTRIBUTING.md
  • The title of the PR is clear and informative
  • The appropriate ChangeLog.md file(s) has been updated:
    • For any service, the ChangeLog.md file can be found at src/{{SERVICE}}/{{SERVICE}}/ChangeLog.md
    • A snippet outlining the change(s) made in the PR should be written under the ## Upcoming Release header -- no new version header should be added
  • The PR does not introduce breaking changes
  • If applicable, the changes made in the PR have proper test coverage
  • For public API changes to cmdlets:
    • a cmdlet design review was approved for the changes in this repository (Microsoft internal only)
      • {Please put the link here}
    • the markdown help files have been regenerated using the commands listed here

@isra-fel isra-fel marked this pull request as ready for review May 30, 2022 00:57
@daandupau
Copy link

Can this be merged, our pipelines are not working because of this.

@BasBerk
Copy link

BasBerk commented Jun 2, 2022

Here the same, this bug is causing us major headaches

@StoneNLD
Copy link

StoneNLD commented Jun 3, 2022

pipelines are not working with task AzurePowershell anymore, please get this merged.

@VeryEarly VeryEarly merged commit 22377b6 into Azure:main Jun 7, 2022
@isra-fel isra-fel deleted the 18304-import-module-azaccounts-throws-an-exception-if-2-environment-vars-differ-only-by-case branch June 8, 2022 03:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Import-Module Az.Accounts throws an exception if 2 environment vars differ only by case
5 participants