Note that there are some explanatory texts on larger screens.

plurals
  1. POPowershell - why is exception treated differently depending on stderr redirection/how to access "multiple" exceptions in a catch?
    primarykey
    data
    text
    <p>This question is related to the question here:</p> <p><a href="https://stackoverflow.com/questions/14575734/suppress-sqlpackage-exe-warnings-errors-in-powershell-when-triggered-using-tfs-b">Suppress sqlpackage.exe warnings/errors in Powershell when triggered using TFS build</a></p> <p>However I have a problem with the workaround that I'm developing, shown below</p> <pre><code> try { &amp; "C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin\SqlPackage.exe" /SourceFile:"$dacpac" /Profile:"$dbProfile" /p:UnmodifiableObjectWarnings=false /Action:Publish 2&gt;&amp;1 } catch { Write-Host "Exception: $_" if($_.TargetObject -like $Pattern) { Write-Host "Known exception - treat as warning" } if($LastExitCode -ne 0) { throw "An error occurred deploying database. Please examine the log to determine the nature of the error" } } </code></pre> <p>If I don't redirect stderr to stdout, when sqlpackage logs a warning, the process indicates a failure.</p> <p>If I redirect stderr to stdout in the previous command, when the sqlpackage.exe throws a warning the process is able to complete, but once it has completed an exception is thrown. I can then examine the exception text, which will be the same as my known exception, and I can safely ignore it. </p> <p>However something as well as the warning is logged by sqlpackage - i.e. an actual failure error, I'm unable to determine the additional text of the exception. Inside the catch, all I can see is the warning message. If I remove the stderr redirection, the full output is logged, which is an error relating to permissions.</p> <p>Therefore, my script succeeds when it should, and ignores warnings that I don't care about it. It fails when I want it to as well, but I can't then output the appropriate log messages. I then need to edit my deployment script, rerun the deployment etc. etc., all fiddly, and not repeatable.</p> <p>Any tips would be much appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload