Skip to content

Commit

Permalink
Fixes#200 no exception error handling during absent state (#203)
Browse files Browse the repository at this point in the history
* Fixes#200 no exception error handling during absent state

* Fixes#200 change in syntax, easier to read/parse

---------

Co-authored-by: Chris Gallagher <[email protected]>
  • Loading branch information
git-cgallagher and Chris Gallagher authored Aug 29, 2023
1 parent 104572c commit 247936b
Show file tree
Hide file tree
Showing 2 changed files with 14 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
14 changes: 12 additions & 2 deletions plugins/modules/database.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,18 @@ try {

if ($state -eq "absent") {
if ($null -ne $existingDatabase) {
$existingDatabase | Remove-DbaDatabase -WhatIf:$checkMode -EnableException -Confirm:$false
$module.Result.changed = $true
try {
$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("Database [$database] was not dropped. " + $droppedDatabase.Status)
}
}
catch {
$module.FailJson("An exception occurred while trying to drop database [$database].", $_)
}
}
$module.ExitJson()
}
Expand Down

0 comments on commit 247936b

Please sign in to comment.