runner icon indicating copy to clipboard operation
runner copied to clipboard

The default shell for Windows (Powershell) does not show the stderr/stdout on exit error

Open evandrocoan opened this issue 4 years ago • 9 comments

Describe the bug For example, this build my which used the default shell for windows (powershell), did not showed the stdout or stderr of the error. It just says the command exited with some error code. Doing so, you have no ideia from which line the error comes from or what was happening: https://github.com/evandroforks/anki/runs/522520124?check_suite_focus=true#step:5:10 image

This problem does not happens if I change the shell to cmd: https://github.com/evandroforks/anki/runs/522428852?check_suite_focus=true#step:5:26 image

Question, Bug, or Feature?: "Bug"

Virtual environments affected

  • [ ] macOS 10.15
  • [ ] Ubuntu 16.04 LTS
  • [ ] Ubuntu 18.04 LTS
  • [x] Windows Server 2016 R2
  • [x] Windows Server 2019

evandrocoan avatar Mar 20 '20 17:03 evandrocoan

It's something to do with the new error view in PowerShell 7. Try adding $ErrorView = "NormalView" at the top of the script

hbuckle avatar Mar 21 '20 14:03 hbuckle

Hello @evandrocoan , thank you for the detailed report. This repository manages only content of Hosted images for GA and AzDO, not the build running process. For me, it looks like the issue with actions/runner.

@TingluoHuang , @ericsciple , Hello! Does it make sense to move this issue to your repository for further investigation?

al-cheb avatar Mar 23 '20 07:03 al-cheb

@dakale

ericsciple avatar Mar 23 '20 14:03 ericsciple

The runner captures all output from the shell processes it runs and prints them to the console. In your example it looks like you are comparing two different steps: The first one using pwsh is "Fix choclately install" and the cmd step is "Set up ripgrep ... ", so I would expect them to have different outputs.

Are you sure the first step is supposed to be outputting anything?

dakale avatar Mar 23 '20 16:03 dakale

I am certain Powershell never ever tells me when there is an error. It made my life hell for countless occasions. I will never ever use Powershell again with GitHub actions. They are just not worth. This was not the only case. Running the same commands locally on my computer, Powershell is quite verbose about their errors: image

Instead of using Powershell directly, I can just set the shell to cmd and invoke Powershell from it, as I am doing on this rule, on the latest version of that script: https://github.com/evandroforks/anki/actions/runs/62292014/workflow#L101-L106

- name: Set up scoop, gettext, ripgrep
  shell: cmd
  run: |
    echo on
    powershell -executionpolicy bypass "& Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')"
    scoop install -g gettext ripgrep

evandrocoan avatar Mar 24 '20 16:03 evandrocoan

@hbuckle wrote:

It's something to do with the new error view in PowerShell 7. Try adding $ErrorView = "NormalView" at the top of the script

That did it for me! Thanks! :smile:

As per the MS docs, $ErrorView is now defaulted to ConciseView. As @hbuckle suggested, I simply added:

$ErrorView = 'NormalView'

And now get the more detailed output I'd expected.

pcolby avatar Apr 12 '20 11:04 pcolby

@pcolby Thanks for reporting back! @alepauly, this $ErrorView = 'NormalView' should be the default value because it is quite frustrating having PowerShell hiding from you what went wrong.

evandrocoan avatar Apr 12 '20 17:04 evandrocoan

@ericsciple @dakale should we set $ErrorView = 'NormalView' when we generate the .ps1 script?

TingluoHuang avatar Jun 08 '20 17:06 TingluoHuang

$ErrorView = 'NormalView'

Is it possible to set this for all pwsh invocations in a given workflow file? (explicit use of pwsh or by OS default)

ihnorton avatar Nov 22 '21 18:11 ihnorton

Is it possible to set this for all pwsh invocations in a given workflow file? (explicit use of pwsh or by OS default)

I'd recommend setting a job level ENV for ErrorView.

fhammerl avatar Feb 07 '23 10:02 fhammerl

We have decided against modifying the powershell default behaviour here. As a workaround, set the ErrorView ENV to NormalView or ConciseView on the job or step level, or directly in your script.ps1 file that you're executing.

fhammerl avatar Feb 07 '23 10:02 fhammerl