tag:help.appveyor.com,2012-11-13:/discussions/questions/48697-what-is-the-difference-between-powershell-warnings-and-error-preferences-in-production-and-debug-modeAppVeyor: Discussion 2020-09-16T21:03:06Ztag:help.appveyor.com,2012-11-13:Comment/483949782020-06-10T12:58:57Z2020-06-10T12:58:57ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Some of the commands I execute during test phase produce output as INFO and NOTICE. Powershell flags this as an error and raises an exception during production mode but when I run the same commands in debug mode there is no error. I think there may be some difference in the error preferences. Can someone help me diagnose this ?</p></div>kartikohri13tag:help.appveyor.com,2012-11-13:Comment/483949782020-06-10T19:27:17Z2020-06-10T19:27:17ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Could you drop a link to a build please?</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/483949782020-06-11T09:04:28Z2020-06-11T09:04:28ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Please see <a href="https://ci.appveyor.com/project/amCap1712/pljava/builds/33437118">https://ci.appveyor.com/project/amCap1712/pljava/builds/33437118</a> .<br>
At the end of the build, Powershell fails the build with an exception<br>
raised due to debug output. This issue does not happen in debug builds.</p></div>kartikohri13tag:help.appveyor.com,2012-11-13:Comment/483949782020-06-11T20:52:56Z2020-06-11T20:52:56ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>It's how PowerShell custom host is working. Windows PowerShell treats all writes to StdErr as exceptions.</p>
<p>To workaround that issue I'd move <a href="https://github.com/amCap1712/pljava/blob/23d6f17ae25a178b1e506e526121b9f1370073a0/appveyor.yml#L12-L37">everything starting from <code>ps:</code></a> to a separate <code>.ps1</code> scripts and then call them from <code>appveyor.yml</code> as:</p>
<pre>
<code>- powershell .\script.ps1</code>
</pre>
<p>...or if <code>psql</code> command line has some "quiet" switch suppressing those messages that could work too.</p>
<p>...or you can use this great function (we use it while building images) to run process with right redirection or with suppressing StdErr: <a href="https://github.com/appveyor/build-images/blob/master/scripts/Windows/common.ps1#L20-L113">https://github.com/appveyor/build-images/blob/master/scripts/Window...</a> Usage examples: <a href="https://github.com/appveyor/build-images/search?q=Start-ProcessWithOutput&unscoped_q=Start-ProcessWithOutput">https://github.com/appveyor/build-images/search?q=Start-ProcessWith...</a></p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/483949782020-06-12T03:06:07Z2020-06-12T03:06:07ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Thanks for the help. Could you explain why merely moving commands from<br>
appveyor.yml to a .ps1 script can fixt his issue?</p></div>kartikohri13tag:help.appveyor.com,2012-11-13:Comment/483949782020-06-12T05:05:59Z2020-06-12T05:05:59ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>The whole point of that is redirecting StdErr to StdOut.</p></div>Feodor Fitsnertag:help.appveyor.com,2012-11-13:Comment/483949782020-07-16T04:16:24Z2020-07-16T04:16:27ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Can someone explain why adding <code>2>&1</code> after a command in <code>ps:</code> mode, which is <a href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-7#examples">covered in the PowerShell docs</a> for the exact purpose, won't work on AppVeyor?</p></div>Chapman Flacktag:help.appveyor.com,2012-11-13:Comment/483949782020-07-17T03:08:44Z2020-07-17T03:08:44ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>I may have hit the mother lode of information on this PowerShell behavior, in these two GitHub issues: <a href="https://github.com/PowerShell/PowerShell/issues/3996">3996</a> and <a href="https://github.com/PowerShell/PowerShell/issues/4002">4002</a>.</p>
<p>When I started a separate instance of PowerShell and ran the external command from that, the stuff that command wrote on stderr never showed up in the log at all, it was just gone. Adding the PowerShell syntax <code>2>&1</code> made it show up in the log, merged with the stdout data. <em>But that was not all it did</em>. (On a POSIX system, that <em>is</em> all that syntax does; it simply makes one file descriptor a dup of another.)</p>
<p>Under PowerShell, the formerly "stderr" data getting merged into "stdout" <em>still got modified by PowerShell</em> (or .NET or whatever layer is doing that). Something tried to assemble a structured 'error record' out of the start of the stderr data and display it as an exception. It all got strangely reformatted, as apparently the convert-stderr-to-error-records code deals poorly with stderr data arriving in fragments of lines (as often seen from external programs that report progress).</p>
<p>Those two GitHub issues contain a trove of information on what's going on.</p></div>Chapman Flacktag:help.appveyor.com,2012-11-13:Comment/483949782020-07-17T16:58:41Z2020-07-17T16:58:41ZWhat is the difference between Powershell warnings and error preferences in production and debug mode?<div><p>Right, something is definitely wrong there. Thanks for sharing your investigation.</p></div>Feodor Fitsner