Azure / Azure/azure-powershell

Linux: Import of Az.Accounts fails with obscure error message when $HOME is not set

Open
#24,813 1 comment 0 reactions 1 assignee Claimed by @Nickcandy View on GitHub
Accounts Azure PS Team customer-reported feature-request Tracking
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

When importing Az.Accounts on Linux, the startup checks assume that $HOME is set to a non-empty string. Some CI servers (TeamCity at least) do not set this by default.

The error is thrown in https://github.com/Azure/azure-powershell/blob/cd91bc298e717aaf49b4cd456885cce57de0cd49/src/Accounts/Accounts/StartupScripts/AzError.ps1#L32

Maybe it would be better to check whether $HOME is set before calling Join-Path there, and either skip the check or produce a meaningful error message.

### Issue script & Debug output

```PowerShell
Set-Variable -Name Home -Value "" -Force
Import-Module Az.Accounts

Join-Path: {REDACTED}/.local/share/powershell/Modules/Az.Accounts/2.19.0/StartupScripts/AzError.ps1:32
Line |
32 | $pathToInstallationChecks = Join-Path (Join-Path $HOME ".Azure") …
| ~~~~~
| Cannot bind argument to parameter 'Path' because it is an empty string.
InvalidOperation: {REDACTED}/.local/share/powershell/Modules/Az.Accounts/2.19.0/StartupScripts/AzError.ps1:34
Line |
34 | if (!(Test-Path $pathToInstallationChecks -ErrorAction Ignore))
| ~~~~~~~~~~~~~~~~~~~~~~~~~
| The variable '$pathToInstallationChecks' cannot be retrieved because it has not been
| set.
```

### Environment data

```PowerShell
Name Value
---- -----
PSVersion 7.4.1
PSEdition Core
GitCommitId 7.4.1
OS Ubuntu 22.04.4 LTS
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```

### Module versions

```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.19.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
```

### Error output

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.