Re: Help getting custom exception to print message when using the stdout reporter

13 views
Skip to first unread message
Message has been deleted

Leonard Ehrenfried

unread,
Nov 28, 2016, 9:30:26 AM11/28/16
to scalatest-users
Try overriding the method "getMessage". 


Best
Leonard

On Tuesday, November 22, 2016 at 11:24:24 PM UTC+1, Sean Callahan wrote:
In my code I have the following exception 

class HttpRequestException(val response: HttpResponse) extends Throwable {
...
  override def toString: String = {
    s"Received unexpected status code. \n Status Code: [${response.status}] \n Body: $body \n Headers: $headers"
  }
}

In my tests, there are cases where this can be thrown. When I run the tests from IntelliJ and this exception is hit, the output looks like...

com.twitter.dataproducts.clients.http.HttpRequestException was thrown.
Received unexpected status code. 
 Status Code: [422 Unprocessable Entity] 
 Body: ....
 Headers: 
Date: Tue, 22 Nov 2016 20:06:48 GMT
        ...

at com.twitter.dataproducts.clients.akka.Flows$$anonfun$checkResponseForError$1.apply(Flows.scala:25)
at com.twitter.dataproducts.clients.akka.Flows$$anonfun$checkResponseForError$1.apply(Flows.scala:22)
at akka.stream.impl.fusing.Map$$anon$8.onPush(Ops.scala:42)

This information is super useful in debugging exactly what went wrong. 

Now when I run this same test from my command line using "-o" for the stdout reporter, all I end up getting is...

- test that failed *** FAILED ***
    com.twitter.dataproducts.clients.http.HttpRequestException:
    at com.twitter.dataproducts.clients.akka.Flows$$anonfun$checkResponseForError$1.apply(Flows.scala:25)
    at com.twitter.dataproducts.clients.akka.Flows$$anonfun$checkResponseForError$1.apply(Flows.scala:22)
    at akka.stream.impl.fusing.Map$$anon$8.onPush(Ops.scala:43)

As you can see, the all that useful information is gone. Base on the ":" trailing the exception type, I am guessing that I am just doing something wrong to get this to print out in that reporter. 

I also cannot specifically use an info() in the test as I am building up a framework for other devs to use, so setting this up to print behind the scenes is important.

As a note, I am using scalatest 3.0. 

Sean Callahan

unread,
Nov 28, 2016, 2:38:21 PM11/28/16
to scalatest-users
This thread got duplicated. Bill replied at https://groups.google.com/forum/#!topic/scalatest-users/HYV86iCjIn0. I'll continue over there. As I noted on that thread. overriding getMessage did not work. 
Reply all
Reply to author
Forward
0 new messages