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

Fake throws when handled exceptions happen within a task. #1079

Closed
matthid opened this issue Jan 16, 2016 · 6 comments
Closed

Fake throws when handled exceptions happen within a task. #1079

matthid opened this issue Jan 16, 2016 · 6 comments

Comments

@matthid
Copy link
Member

matthid commented Jan 16, 2016

Given the following FAKE-Script

open Fake
Target "Test" (fun _ ->
  try
    [ "test.dll" ]
      |> NUnit (fun _ -> failwith "test")
  with
  | exn ->
    ()
)

RunTargetOrDefault "Test"

Results in:

$ ./packages/FAKE/tools/FAKE.exe src/testScript.fsx
Building project with version: LocalBuild
Shortened DependencyGraph for Target Test:
<== Test

The resulting target order is:
 - Test
Starting Target: Test
Finished Target: Test
Running build failed.
Error:
System.Exception: Invalid tag structure. Trying to close target tag but stack is [task; target]
   at Fake.TraceHelper.closeTag@123.Invoke(String message) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 123
   at Fake.TraceHelper.closeTag(String tag) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 123
   at Fake.TraceHelper.traceEndTarget(String name) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 139
   at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 485

---------------------------------------------------------------------
Build Time Report
---------------------------------------------------------------------
Target     Duration
------     --------
Test       00:00:00.1317542
Total:     00:00:00.1722803
Status:    Failure
---------------------------------------------------------------------
  1) System.Exception: Invalid tag structure. Trying to close target tag but stack is [task; target]
   at Fake.TraceHelper.closeTag@123.Invoke(String message) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 123
   at Fake.TraceHelper.closeTag(String tag) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 123
   at Fake.TraceHelper.traceEndTarget(String name) in C:\code\fake\src\app\FakeLib\TraceHelper.fs:line 139
   at Fake.TargetHelper.runSingleTarget(TargetTemplate`1 target) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 485
---------------------------------------------------------------------

I don't thought this is expected behaviour, so I wanted to go ahaid and fix it. I noticed that the problem is that traceEndTask is not properly in finally blocks. However, as the change is quite invasive, I wanted to ask here first: Should they be in a finally block or is this by-design?

@pushasha
Copy link

I'm having the same issue when running my tests. After all the tests are run, FAKE throws the InvalidTagStructure exception mentioned above when there are failures, even if the failure-related exception is caught. This is problematic, as the "invalid tag structure", not the failing unit tests, is what shows up as the reason for build failure on our CI tools.

@matthid
Copy link
Member Author

matthid commented Feb 16, 2016

btw my current workaround is to call the missing traceEndTask manually, which is obviously nasty (and will break again when the bug is fixed)

@pushasha
Copy link

@matthid Thank you for the workaround! Even though it's "nasty", it definitely helps -- It'll keep people from telling me my scripts are "broken" when their unit tests fail and they see a FAKE exception rather than the actual test failure.

@TangoMikeOscar
Copy link

I am getting this issue also when trying to catch errors from a nuget publish. Please fix!

@matthid Could you post your traceEndTask fix so I can see what it looks like and how it would fit into my flow? Thanks

@matthid
Copy link
Member Author

matthid commented Apr 24, 2016

@stevephillips

Please fix!

Usually the best way to get it fixed is to send a Pull-Request ;)

The following works for me:

try
  files
    |> NUnit (fun p -> raise <| MyError ("T."))
  true
with
| MyError s ->
  traceEndTask "NUnit" (files |> separated ", ") // Workaround for https://github.com/fsharp/FAKE/issues/1079
  false

@dsyme
Copy link
Collaborator

dsyme commented Oct 6, 2016

Fixed by @0x53A - great!

@dsyme dsyme closed this as completed Oct 6, 2016
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

4 participants