Skip to content

Commit

Permalink
Fixes#200 no exception error handling during absent state
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Gallagher committed Aug 28, 2023
1 parent 104572c commit d2d6c5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
minor_changes:
- Fixes error handling for Remove-DbaDatabase when joined to AvailabilityGroup, exception was not being thrown so we have to parse Status
12 changes: 10 additions & 2 deletions plugins/modules/database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,16 @@ try {

if ($state -eq "absent") {
if ($null -ne $existingDatabase) {
$existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false
$module.Result.changed = $true
$droppedDatabase = ($existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false)
if ($droppedDatabase.Status -eq "Dropped") {
$module.Result.changed = $true
}
elseif ($droppedDatabase.Status -ne "Dropped") {
$module.FailJson("Drop database [$database] failed. " + $droppedDatabase.Status)
}
else {
$module.FailJson("Drop database [$database] failed.", $_)
}
}
$module.ExitJson()
}
Expand Down

0 comments on commit d2d6c5c

Please sign in to comment.