mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
become win: better error messages and docs update (#39936)
* become win: better error messages and docs update * Fix syntax error and added changelog fragment
This commit is contained in:
parent
44ab948e5d
commit
e0813d7d47
4 changed files with 72 additions and 12 deletions
|
@ -1161,10 +1161,14 @@ namespace Ansible
|
|||
Write-Output ([System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes((Write-Output $output))))
|
||||
} # end exec_wrapper
|
||||
|
||||
Function Dump-Error ($excep) {
|
||||
Function Dump-Error ($excep, $msg=$null) {
|
||||
$eo = @{failed=$true}
|
||||
|
||||
$eo.msg = $excep.Exception.Message
|
||||
$exception_message = $excep.Exception.Message
|
||||
if ($null -ne $msg) {
|
||||
$exception_message = "$($msg): $exception_message"
|
||||
}
|
||||
$eo.msg = $exception_message
|
||||
$eo.exception = $excep | Out-String
|
||||
$host.SetShouldExit(1)
|
||||
|
||||
|
@ -1243,7 +1247,7 @@ Function Run($payload) {
|
|||
try {
|
||||
$logon_type, $logon_flags = Parse-BecomeFlags -flags $payload.become_flags
|
||||
} catch {
|
||||
Dump-Error -excep $_
|
||||
Dump-Error -excep $_ -msg "Failed to parse become_flags '$($payload.become_flags)'"
|
||||
return $null
|
||||
}
|
||||
|
||||
|
@ -1285,7 +1289,7 @@ Function Run($payload) {
|
|||
[Console]::Error.WriteLine($stderr.Trim())
|
||||
} Catch {
|
||||
$excep = $_
|
||||
Dump-Error $excep
|
||||
Dump-Error -excep $excep -msg "Failed to become user $username"
|
||||
} Finally {
|
||||
Remove-Item $temp -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue