Closed jpomfret closed 3 months ago
Hi Jess!
All three warning messages are generated by "Write-Message". To be able to raise an exception when using EnableException, we would have to change some or all of them to "Stop-Function".
I would suggest to change line 768 of Restore-DbaDatabase (Write-Message -Level Warning -Message "Database $DbUnverified failed testing, skipping"
) to Stop-Function -Message "Database $DbUnverified failed testing, skipping"
.
We would have to think about a good message, as the current message is ok for EnableException:$false, but maybe not the best for EnabledException:$true.
Here is a screenshot from my tests:
@jpomfret Can you help with a good message? I can do the coding and open the pull request.
Hey @andreasjordan - what about Database $DbUnverified unable to be restored
, it would be nice to also collect why it couldn't be restored but I'm not sure how easy that is looking at the code
The details are still shown in the warning, so I changed the message to Database $DbUnverified unable to be restored, see warnings for details
. What do you think?
Yeah I like that - sounds good!
Verified issue does not already exist?
I have searched and found no existing issue
What error did you receive?
I got this warning - even when specifying
-EnableException
it doesn't change to throw an error and therefore can't be trappedSteps to Reproduce
Need to already have a
pubs
database existing and then try and restore a second with a new namePlease confirm that you are running the most recent version of dbatools
2.1.5
Other details or mentions
No response
What PowerShell host was used when producing this error
VS Code (terminal), VS Code (integrated terminal)
PowerShell Host Version
SQL Server Edition and Build number
Microsoft SQL Server 2019 (RTM-CU18) (KB5017593) - 15.0.4261.1 (X64) Sep 12 2022 15:07:06 Copyright (C) 2019 Microsoft Corporation Developer Edition (64-bit) on Linux (Ubuntu 20.04.5 LTS)
.NET Framework Version
.NET 7.0.15