jantari / LSUClient

Orchestrate driver, BIOS/UEFI and firmware updates for Lenovo computers 👨‍💻
https://jantari.github.io/LSUClient-docs/
MIT License
208 stars 22 forks source link

RuntimeException in Install-BiosUpdate.ps1 if $PackageDirectory\winuptp.log doesn't exist #84

Closed grozmb closed 1 year ago

grozmb commented 1 year ago

Version

1.5.3

Computer Model

21CES05100

Problem

Installing this BIOS update: ID : n3auj17w Title : BIOS Update Utility - 10/11 Type : BIOS

with the command Install-LSUpdate $updates[1] -Verbose (I selected only this one in the $updates array)

...produces a RuntimeException AUSFÜHRLICH: Extracting package n3auj17w ... DEBUG: Starting external process: File: C:\Users\Administrator\AppData\Local\Temp\LSUPackages\n3auj17w\n3auj17w.exe Arguments: /VERYSILENT /DIR=C:\Users\ADMINI~1\AppData\Local\Temp\LSUPackages\n3auj17w\ /EXTRACT="YES" WorkingDirectory: C:\Users\ADMINI~1\AppData\Local\Temp\LSUPackages\n3auj17w DEBUG: Added runspace process 13244 to job: True AUSFÜHRLICH: Installing package n3auj17w ... DEBUG: Begin Get-BitLockerVolume(C:) DEBUG: Begin Get-BitLockerVolumeInternal(C:) DEBUG: Begin Get-Win32EncryptableVolumeInternal(C:) DEBUG: End Get-Win32EncryptableVolumeInternal. Return Win32_EncryptableVolume (DeviceID = "\?\Volume{de7fb886-96a5-455a-98c3-64c3...) DEBUG: ComputerName: G11020640. MountPoint: C:. LockStatus: 0 DEBUG: EncryptionMethod: 7 DEBUG: Win32EncryptableVolume.IsAutoUnlockEnabled() returned error @{IsAutoUnlockEnabled=False; ReturnValue=2150694937; VolumeKeyProtectorID={00000000-0000-0000-0000-000000000000}; PSComputerName=}.ReturnValue DEBUG: AutoUnlockEnabled: . AutoUnlockKeyProtectorId: DEBUG: AutoUnlockKeyStored: False DEBUG: MetaDataVersion: 2 DEBUG: ConversionStatus: 1. WipingStatus: 0. EncryptionPercentage: 100. WipePercentage: 0 DEBUG: ProtectionStatus: 0. DEBUG: VolumeType: OperatingSystem. CapacityGB: 476.715816497803 DEBUG: KeyProtectorIds: {012408B3-7519-455F-873D-D8CBA096F1D4} {C0B1EF43-0AA3-4C0E-98E5-01A91936F177} DEBUG: KeyProtector[0] = KeyProtectorId: {012408B3-7519-455F-873D-D8CBA096F1D4}. KeyProtectorType: 1 DEBUG: KeyProtector[1] = KeyProtectorId: {C0B1EF43-0AA3-4C0E-98E5-01A91936F177}. KeyProtectorType: 3 DEBUG: KeyProtectorRecoveryPassword found DEBUG: End Get-BitLockerVolumeInternal. Return C: DEBUG: End Get-BitLockerVolume AUSFÜHRLICH: This is a ThinkPad-style BIOS update DEBUG: Starting external process: File: C:\Users\ADMINI~1\AppData\Local\Temp\LSUPackages\n3auj17w\winuptp.exe Arguments: -s WorkingDirectory: C:\Users\ADMINI~1\AppData\Local\Temp\LSUPackages\n3auj17w DEBUG: Added runspace process 15020 to job: True AUSFÜHRLICH: C:\Users\ADMINI~1\AppData\Local\Temp\LSUPackages\n3auj17w\winuptp.log AUSFÜHRLICH: LogMessage null: True

Objekt vom Typ "BiosUpdateInfo. Das Objekt des Typs "System.Management.Automation.PSObject" kann nicht in Typ "System.String[]" umgewandelt werden." kann nicht erstellt werden. In C:\Program Files (x86)\Common Files\enteo\RepositoryCache\157554\rev\1\Extern$\SupportFiles\LSUClient\private\Install-BiosUpdate.ps1:40 Zeichen:20 return [ExternalProcessResult]::new(


     CategoryInfo          : InvalidArgument: (:) [], RuntimeException
     FullyQualifiedErrorId : ObjectCreationError

### Additional context

I figured this happens because this function in Install-BiosUpdate.ps1

[array]$LogMessage = if ($Log = Get-Content -LiteralPath "$PackageDirectory\winuptp.log" -ErrorAction SilentlyContinue) {
                $NonEmptyPredicate = [Predicate[string]] { -not [string]::IsNullOrWhiteSpace($args[0]) }
                $LogFirstNonEmpty = [array]::FindIndex([string[]]$Log, $NonEmptyPredicate)
                if ($LogFirstNonEmpty -ne -1) {
                    $LogLastNonEmpty = [array]::FindLastIndex([string[]]$Log, $NonEmptyPredicate)
                    $Log[$LogFirstNonEmpty..$LogLastNonEmpty]
                }
            }

Doesn't return anything if winuptp.log does not exist. So $LogMessage is $null.
I fixed it simply by adding 
`else { "" }`
right after this function. This prevents the exception.
jantari commented 1 year ago

Thanks for reporting, I remember this bug / unexpected behavior of PowerShell has bitten me before.

There's some issues for it as well: https://github.com/PowerShell/PowerShell/issues/10426 and https://github.com/PowerShell/PowerShell/issues/13651 but no official fix in sight yet.

Your workaround is exactly what has to be done to avoid this, I had done the same thing in other places too, such as:

https://github.com/jantari/LSUClient/blob/0a4039120602cf87f5f3a970622f02d35927d447/public/Get-LSUpdate.ps1#L257-L260

but didn't see that this function would be affected by the same thing too.

If you like you can submit a PR with the fix you proposed :)

jantari commented 1 year ago

I've implemented the fix myself now, will be out with 1.5.4

0785bd9

jantari commented 1 year ago

Version 1.5.4 is released and includes this fix