question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using `should throw` does not show the raised exception, only the string version of the lambda

See original GitHub issue

Description

With FsUnit.XUnit using should throw, the report of “Expected vs Actual” shows the string version of the lambda function that was used to pass into the test.

Another issue is that, when the result type of the function-under-test is not unit, the test will always fail with a similar vague message.

Repro steps

You can repro with this test:

// XUnit test
[<Fact>]
let ``Test raising exception`` () = task {
    fun () -> failwith "help" |> ignore
    |> should throw typeof<HttpRequestException>  // should fail

Expected behavior

Something like this is expected, which would clearly indicate what goes wrong.

FsUnit.Xunit+MatchException : Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: System.Net.Http.HttpRequestException
Actual:   System.Exception

Actual behavior

But this is shown instead, which suggests there wasn’t an exception at all and the type is wrong.

FsUnit.Xunit+MatchException : Exception of type 'FsUnit.Xunit+MatchException' was thrown.
Expected: System.Net.Http.HttpRequestException
Actual:   <fun:Pipe #1 input at line 112@112>

Known workarounds

None that I found.

Related information

  • Operating system: Win11
  • Branch: latest from Nuget
  • Using .NET 6.0
  • Using FsUnit.Xunit

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
abelbraaksmacommented, Sep 9, 2022

Great stuff, tx!

1reaction
CaptnCodrcommented, Sep 1, 2022

@abelbraaksma Yes, I see. It should be similar to the NUnit output, right:

Message: 
  Expected: System.Net.Http.HttpRequestException
  But was:  System.Exception: help
   at <StartupCode$FsUnit-NUnit-Test>.$ShouldFailTests.Pipe #1 input at line 33@33.Invoke(Unit unitVar0) in C:\Users\const\github\repos\FsUnit\tests\FsUnit.NUnit.Test\shouldFailTests.fs:line 33
   at FsUnit.TopLevelOperators.y@37.Invoke()
--- End of stack trace from previous location ---
   at NUnit.Framework.Internal.ExceptionHelper.Rethrow(Exception exception)
   at NUnit.Framework.Internal.Reflect.DynamicInvokeWithTransparentExceptions(Delegate delegate)
   at NUnit.Framework.Internal.ExceptionHelper.RecordException(Delegate parameterlessDelegate, String parameterName)

I will analyse this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Define a lambda expression that raises an Exception
@gnibbler Some context: I wanted to define a function def g(f, e) that calls f in the happy case and e if an...
Read more >
AWS Lambda function errors in Java
This page describes how to view Lambda function invocation errors for the Java runtime using the Lambda console and the AWS CLI.
Read more >
How to Use Python Lambda Functions
In this step-by-step tutorial, you'll learn about Python lambda functions. You'll see how they compare with regular functions and how you can use...
Read more >
Exception-handling statements - throw and try, catch, finally
Use the throw statement to throw an exception. Use the try statement to catch and handle exceptions that might occur during execution of...
Read more >
10.2 Exceptions
Whenever a primitive error occurs in Racket, an exception is raised. ... (but the semi-colon should be omitted if ‹continued-message› is not present)....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found