What is the difference between Powershell warnings and error preferences in production and debug mode?

kartikohri13's Avatar


10 Jun, 2020 12:58 PM

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 ?

  1. Support Staff 1 Posted by Feodor Fitsner on 10 Jun, 2020 07:27 PM

    Feodor Fitsner's Avatar

    Could you drop a link to a build please?

  2. 2 Posted by kartikohri13 on 11 Jun, 2020 09:04 AM

    kartikohri13's Avatar

    Please see https://ci.appveyor.com/project/amCap1712/pljava/builds/33437118 .
    At the end of the build, Powershell fails the build with an exception
    raised due to debug output. This issue does not happen in debug builds.

  3. Support Staff 3 Posted by Feodor Fitsner on 11 Jun, 2020 08:52 PM

    Feodor Fitsner's Avatar

    It's how PowerShell custom host is working. Windows PowerShell treats all writes to StdErr as exceptions.

    To workaround that issue I'd move everything starting from ps: to a separate .ps1 scripts and then call them from appveyor.yml as:

    - powershell .\script.ps1

    ...or if psql command line has some "quiet" switch suppressing those messages that could work too.

    ...or you can use this great function (we use it while building images) to run process with right redirection or with suppressing StdErr: https://github.com/appveyor/build-images/blob/master/scripts/Window... Usage examples: https://github.com/appveyor/build-images/search?q=Start-ProcessWith...

  4. 4 Posted by kartikohri13 on 12 Jun, 2020 03:06 AM

    kartikohri13's Avatar

    Thanks for the help. Could you explain why merely moving commands from
    appveyor.yml to a .ps1 script can fixt his issue?

  5. Support Staff 5 Posted by Feodor Fitsner on 12 Jun, 2020 05:05 AM

    Feodor Fitsner's Avatar

    The whole point of that is redirecting StdErr to StdOut.

  6. 6 Posted by Chapman Flack on 16 Jul, 2020 04:16 AM

    Chapman Flack's Avatar

    Can someone explain why adding 2>&1 after a command in ps: mode, which is covered in the PowerShell docs for the exact purpose, won't work on AppVeyor?

  7. 7 Posted by Chapman Flack on 17 Jul, 2020 03:08 AM

    Chapman Flack's Avatar

    I may have hit the mother lode of information on this PowerShell behavior, in these two GitHub issues: 3996 and 4002.

    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 2>&1 made it show up in the log, merged with the stdout data. But that was not all it did. (On a POSIX system, that is all that syntax does; it simply makes one file descriptor a dup of another.)

    Under PowerShell, the formerly "stderr" data getting merged into "stdout" still got modified by PowerShell (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).

    Those two GitHub issues contain a trove of information on what's going on.

  8. Support Staff 8 Posted by Feodor Fitsner on 17 Jul, 2020 04:58 PM

    Feodor Fitsner's Avatar

    Right, something is definitely wrong there. Thanks for sharing your investigation.

  9. Feodor Fitsner closed this discussion on 16 Sep, 2020 09:03 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac