Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion public/Export-DbaDacPackage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ function Export-DbaDacPackage {

#check that at least one of the DB selection parameters was specified
if (!$AllUserDatabases -and !$Database) {
Stop-Function -Message "Either -Database or -AllUserDatabases should be specified" -Continue
# No -Continue here: this block has no enclosing loop, so the continue would escape the command
# and eat an iteration of whatever loop the caller runs in (#10638).
Stop-Function -Message "Either -Database or -AllUserDatabases should be specified"
return
}
#Check Option object types - should have a specific type
if ($Type -eq 'Dacpac') {
Expand Down
17 changes: 16 additions & 1 deletion tests/Export-DbaDacPackage.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -240,4 +240,19 @@ Describe $CommandName -Tag IntegrationTests {
}
}
}
}

Context "When only ExcludeDatabase is given" {
It "Warns without eating an iteration of the caller's loop" {
# The database selection check used to run Stop-Function -Continue in the process block, where no
# loop encloses it - the continue escaped the command and consumed an iteration of this very loop,
# so the counter stayed at zero (#10638). The check fires before any connection is made.
$loopCount = 0
foreach ($i in 1..3) {
$null = Export-DbaDacPackage -SqlInstance $TestConfig.InstanceSingle -ExcludeDatabase dbatoolsci_none -WarningAction SilentlyContinue
$loopCount++
}
$loopCount | Should -Be 3
($WarnVar -join " ") | Should -BeLike "*Either -Database or -AllUserDatabases should be specified*"
}
}
}