Repository: conan-io/conan

Issue:
[bug] crash on Windows when trying to obtain USERNAME from environment
<!--
  Please don't forget to update the issue title.
  Include all applicable information to help us reproduce your problem.

  To help us debug your issue please explain:
-->

### Environment Details (include every applicable attribute)
  * Operating System+version: Windows 11
  * Compiler+version: N/A
  * Conan version: 1.48
  * Python version: 3.10.4

### Steps to reproduce (Include if Applicable)
Powershell in which `USERNAME` is not set as a variable

```powershell
git clone https://github.com/ultimaker/libarcus.git
cd libarcus
git checkout CURA-9177_fix_CI_CT
conan create . arcus/5.0.0-PullRequest0137.67@ultimaker/testing -pr:b cura_build.jinja -pr:h cura_release.jinja --build=missing
```

### Logs (Executed commands with output) (Include/Attach if Applicable)

Traceback
```shell
Traceback (most recent call last):
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\command.py", line 2238, in run
    method(args[0][1:])
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\command.py", line 382, in create
    info = self._conan.create(args.path, name=name, version=version, user=user,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\conan_api.py", line 93, in wrapper
    return f(api, *args, **kwargs)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\conan_api.py", line 388, in create
    deps_install(app=app,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\manager.py", line 58, in deps_install
    deps_graph = graph_manager.load_graph(ref_or_path, create_reference, graph_info, build_modes,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 127, in load_graph
    deps_graph = self._resolve_graph(root_node, profile_host, profile_build, graph_lock,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 289, in _resolve_graph
    deps_graph = self._load_graph(root_node, check_updates, update,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 410, in _load_graph
    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 336, in _recurse_build_requires
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 410, in _load_graph
    self._recurse_build_requires(graph, builder, check_updates, update, build_mode,
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_manager.py", line 336, in _recurse_build_requires
    self._binary_analyzer.evaluate_graph(graph, build_mode, update, remotes, nodes_subset, root)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 431, in evaluate_graph
    self._evaluate_node(node, build_mode, update, remotes)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 202, in _evaluate_node
    self._process_node(node, pref, build_mode, update, remotes)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\client\graph\graph_binaries.py", line 275, in _process_node
    if package_layout.package_id_exists(pref.id) and pref.id in metadata.packages:
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\paths\package_layouts\package_cache_layout.py", line 133, in package_id_exists
    pkg_folder = self.package(PackageReference(self._ref, package_id))
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\paths\package_layouts\package_cache_layout.py", line 32, in wrap
    return path_shortener(p, self._short_paths)
  File "C:\Users\********\AppData\Roaming\Python\Python310\site-packages\conans\util\windows.py", line 88, in path_shortener
    userdomain, username = os.getenv("USERDOMAIN"), os.environ["USERNAME"]
  File "C:\Program Files\Python310\lib\os.py", line 679, in __getitem__
    raise KeyError(key) from None
KeyError: 'USERNAME'

ERROR: 'USERNAME'
```

Environmental variables
```powershell
PS C:\dev\libarcus> gci env:* | sort-object name

Name                           Value
----                           -----                                                                                                                                                                                                                                                                                                                                                                                                 
__INTELLIJ_COMMAND_HISTFILE__  C:\Users\********\AppData\Local\JetBrains\CLion2022.1\terminal\history\libarcus-history                                                                                                                                                                                                                                                                                                              
ALLUSERSPROFILE                C:\ProgramData                                                                                                                                                                                                                                                                                                                                                                                        
APPDATA                        C:\Users\********\AppData\Roaming                                                                                                                                                                                                                                                                                                                                                                    
CommonProgramFiles             C:\Program Files\Common Files                                                                                                                                                                                                                                                                                                                                                                         
CommonProgramFiles(x86)        C:\Program Files (x86)\Common Files                                                                                                                                                                                                                                                                                                                                                                   
CommonProgramW6432             C:\Program Files\Common Files                                                                                                                                                                                                                                                                                                                                                                         
COMPUTERNAME                   ********                                                                                                                                                                                                                                                                                                                                                                                              
ComSpec                        C:\windows\system32\cmd.exe                                                                                                                                                                                                                                                                                                                                                                           
DriverData                     C:\Windows\System32\Drivers\DriverData                                                                                                                                                                                                                                                                                                                                                                
FPS_BROWSER_APP_PROFILE_STRING Internet Explorer                                                                                                                                                                                                                                                                                                                                                                                     
FPS_BROWSER_USER_PROFILE_ST... Default                                                                                                                                                                                                                                                                                                                                                                                               
HOMEDRIVE                      C:                                                                                                                                                                                                                                                                                                                                                                                                    
HOMEPATH                       \Users\********
IDEA_INITIAL_DIRECTORY         C:\
JAVA_HOME                      C:\Program Files\Amazon Corretto\jre8
LOCALAPPDATA                   C:\Users\********\AppData\Local
LOGONSERVER                    \\********
NUMBER_OF_PROCESSORS           12
OneDrive                       C:\Users\********\OneDrive - ***********
OneDriveCommercial             C:\Users\********\OneDrive - ***********
OS                             Windows_NT
Path                           C:\Program Files\Python310\Scripts\;C:\Program Files\Python310\;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0\;C:\windows\System32\OpenSSH\;C:\windows\system32\config\systemprofile\AppData\Local\Microsoft\WindowsApps;C:\Program Files\Amazon Corretto\jre8\bin;C:\Program Files\Git\cmd;C:\Program Files\dotnet\;C:\Users\********\AppDat... 
PATHEXT                        .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.PY;.PYW;.CPL
PROCESSOR_ARCHITECTURE         AMD64
PROCESSOR_IDENTIFIER           Intel64 Family 6 Model 165 Stepping 2, GenuineIntel
PROCESSOR_LEVEL                6
PROCESSOR_REVISION             a502
ProgramData                    C:\ProgramData
ProgramFiles                   C:\Program Files
ProgramFiles(x86)              C:\Program Files (x86)
ProgramW6432                   C:\Program Files
PSModulePath                   C:\Users\********\OneDrive - ***********\Documents\WindowsPowerShell\Modules;C:\Program Files\WindowsPowerShell\Modules;C:\windows\system32\WindowsPow
SESSIONNAME                    Console
SystemDrive                    C:
SystemRoot                     C:\windows
TEMP                           C:\Users\JC9C9~1.SPI\AppData\Local\Temp
TERM_SESSION_ID                d1e664b1-b85c-49eb-85d8-be45055fdd9c
TERMINAL_EMULATOR              JetBrains-JediTerm
TMP                            C:\Users\JC9C9~1.SPI\AppData\Local\Temp
USERDOMAIN_ROAMINGPROFILE      ********
USERPROFILE                    C:\Users\********
windir                         C:\windows

```


Discussion:

Resolving patch:
diff --git a/conans/util/windows.py b/conans/util/windows.py
--- a/conans/util/windows.py
+++ b/conans/util/windows.py
@@ -89,7 +89,7 @@ def path_shortener(path, short_paths):
         domainname = "%s\%s" % (userdomain, username) if userdomain else username
         cmd = r'cacls %s /E /G "%s":F' % (short_home, domainname)
         subprocess.check_output(cmd, stderr=subprocess.STDOUT)  # Ignoring any returned output, quiet
-    except (subprocess.CalledProcessError, EnvironmentError):
+    except (subprocess.CalledProcessError, EnvironmentError, KeyError):
         # cmd can fail if trying to set ACL in non NTFS drives, ignoring it.
         pass
 


Test patch: