Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

When calling FAKE from powershell, it runs successfully then exits with an error #1187

Closed
0x53A opened this issue Mar 25, 2016 · 6 comments
Closed

Comments

@0x53A
Copy link
Contributor

0x53A commented Mar 25, 2016

FAKE Version:

Installing 'FAKE 4.22.8'.
Successfully installed 'FAKE 4.22.8'.

This powershell script

    $ErrorActionPreference = "Stop"
    # restore fake from nuget
    &".\.nuget\nuget.exe" "Install" "FAKE" "-OutputDirectory" "packages" "-ExcludeVersion"
    # and build using fake
    &".\packages\FAKE\tools\Fake.exe" "build.fsx"

Runs successfully and then exits with an error:

...
Hello World from FAKE
Finished Target: Default

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target                       Duration
------                       --------
First                        00:00:00.0002082
RestoreNugget                00:00:03.1739934
DownloadBinaryDependencies   00:00:00.1209889
Clean                        00:00:00.0040734
BuildApp                     00:00:15.0406521
BuildUnitTests               00:00:04.5540232
ExtractTools                 00:00:13.9669876
RunUnitTests                 00:01:12.0171539
CoverageReport               00:00:01.5417982
BuildDocumentation           00:00:17.6886626
HarvestHeat                  00:00:00.2742397
ZipUpOutput                  00:00:02.3542330
BuildSetup                   00:00:29.4801323
Default                      00:00:00.0004666
Total:                       00:02:40.2605144
Status:                      Ok
---------------------------------------------------------------------
FAKE.exe : 
In Zeile:5 Zeichen:2
+     &".\packages\FAKE\tools\Fake.exe" "build.fsx"
+     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError

image

This behaviour does not occur with

'FAKE 4.7.2'.

image

@forki
Copy link
Member

forki commented Mar 27, 2016

It doesn't show an error. What's fake's exit code?
On Mar 25, 2016 15:16, "Lukas Rieger" notifications@github.com wrote:

FAKE Version:

Installing 'FAKE 4.22.8'.
Successfully installed 'FAKE 4.22.8'.

This powershell script

$ErrorActionPreference = "Stop"
# restore fake from nuget
&".\.nuget\nuget.exe" "Install" "FAKE" "-OutputDirectory" "packages" "-ExcludeVersion"
# and build using fake
&".\packages\FAKE\tools\Fake.exe" "build.fsx"

Runs successfully and then exits with an error:

...
Hello World from FAKE
Finished Target: Default


Build Time Report

Target Duration


First 00:00:00.0002082
RestoreNugget 00:00:03.1739934
DownloadBinaryDependencies 00:00:00.1209889
Clean 00:00:00.0040734
BuildApp 00:00:15.0406521
BuildUnitTests 00:00:04.5540232
ExtractTools 00:00:13.9669876
RunUnitTests 00:01:12.0171539
CoverageReport 00:00:01.5417982
BuildDocumentation 00:00:17.6886626
HarvestHeat 00:00:00.2742397
ZipUpOutput 00:00:02.3542330
BuildSetup 00:00:29.4801323
Default 00:00:00.0004666
Total: 00:02:40.2605144

Status: Ok

FAKE.exe :
In Zeile:5 Zeichen:2

  • &".\packages\FAKE\tools\Fake.exe" "build.fsx"
    
  • ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : NotSpecified: (:String) [], RemoteException
    • FullyQualifiedErrorId : NativeCommandError

[image: image]
https://cloud.githubusercontent.com/assets/4236651/14045490/049c991e-f29b-11e5-9f53-9ba379c52b17.png

This behaviour does not occur with

'FAKE 4.7.2'.

[image: image]
https://cloud.githubusercontent.com/assets/4236651/14045682/792a2db8-f29c-11e5-898f-eccc60cd85b9.png


You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub
#1187

@0x53A
Copy link
Contributor Author

0x53A commented Mar 28, 2016

Sorry, I'm on vacation for the next two weeks, but my guess is that it is related to stderr.
(Will see if I can connect remotely to my work pc and test it...)

I think when in prowershell $ErrorActionPreference = "Stop" is set, it converts any EXE writing to stderr into an exception.

Since the exception message is empty, my blind guess is that on exit, FAKE flushes some kind of buffer and writes an empty message to stderr, causing powershell to throw.

Edit

The exit code is 0 (checked with procmon)

I have a repro here: https://github.com/0x53A/fake-issue-1187

The issue seems to be related to output redirection, when running the script normally in powershell, it worked WITHOUT an error, but when running it in powershell-ise or with redirection 2>&1 > out.txt it throws.

forki added a commit that referenced this issue Apr 9, 2016
[Fix #1187] Only write to STDERR if an error happened
@PhilipDaniels
Copy link

Err, is there a way of knowing whether this fix has made it to the package available on nuget.org? I am just checking out FAKE, running through the starter example, and the build.ps1/bat script fails with exactly this error if run from the PowerShell console in Visual Studio. That is as of today, 1 Aug 2016, fake reports version 4.36.0.

@0x53A
Copy link
Contributor Author

0x53A commented Aug 1, 2016

I think the pr #1210 was included in 4.23.6
This fixed the issue for me, but we use a frozen version at work, so it might be that the same issue was reintroduced later. I wanted to create a test for this, but never got to it ...

Also if you look at the pr comments, @matthid mentions that the same issue might happen in other code-paths, maybe you just hit a different one than me.

Regarding powershell, I don't think it is possible to detect $ErrorActionPreference = true, as fake might not even be called directly from powershell, but through a few layers of cmd or other processes. (eg PS -> CMD -> FAKE)

@esterad
Copy link

esterad commented Jan 7, 2017

I think the issue is reintroduced in version 4.48.0. It works fine in 4.47.4 but when upgraded powershell throws exception despite successfully executing FAKE script

@matthid
Copy link
Member

matthid commented Jan 7, 2017

Another way would be to check for an empty string here: https://github.com/fsharp/FAKE/blob/master/src/app/FakeLib/TraceListener.fs#L59 instead of the call-site as in #1210
I think that should at least remove those empty string errors. (On any other case we have at least a string to search for). I also think that is the only case we write to the std-err (might be wrong though)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants