Skip to content

Commit 7bba93b

Browse files
committed
(PA-7407) Add more detailed error information when upgrade fails
This commit outputs information on any error(s) that caused the puppet-agent upgrade on Windows to fail. Previously, when the upgrade fails with a ScriptHalted error, only the error is provided with no other information on why it failed. This commit updates install_puppet.ps1 to put any errors from installer.log into puppet_agent_upgrade_failure.log. Then, in the puppet_agent_upgrade_error, read_content_and_delete_file() will output the error information from the error log then delete the error log.
1 parent 8d062b8 commit 7bba93b

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

files/install_puppet.ps1

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,9 @@ try {
347347
Reset-PuppetresDLL $temp_puppetres
348348
}
349349
"$_" | Out-File -FilePath (Join-Path -Path $state_dir -ChildPath 'puppet_agent_upgrade_failure.log')
350+
# Put relevant errors in puppet_agent_upgrade_failure.log
351+
Get-Content -Path $logfile | Select-String -Pattern "^Error.*$|-- Error" | Add-Content -Path (Join-Path -Path $state_dir -ChildPath 'puppet_agent_upgrade_failure.log')
352+
Get-Content -Path $Logfile -Tail 10 | Add-Content -Path (Join-Path -Path $state_dir -ChildPath 'puppet_agent_upgrade_failure.log')
350353
} finally {
351354
Reset-PuppetServices $services_before
352355
Unlock-Installation $install_pid_lock

lib/puppet/provider/puppet_agent_upgrade_error/puppet_agent_upgrade_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def read_content_and_delete_file(filename)
1919
# In this scenario we need to open the file in binmode and read each line
2020
# individually, then encode the result back to UTF-8 so we can sub out both
2121
# the UTF-16 header \uFEFF and the \r\n line carriages.
22-
File.open(logfile, 'rb:UTF-16LE') { |file| file.readlines }[0].encode!('UTF-8').delete("\uFEFF").delete("\r")
22+
File.open(logfile, 'rb:UTF-16LE') { |file| file.read.encode!('UTF-8').delete("\uFEFF").delete("\r") }
2323
else
2424
File.read(logfile)
2525
end

0 commit comments

Comments
 (0)