Fragment Evaluation Error

2019-07-26 17:08发布

Can someone tell me what "Fragment evaluation error" means, or where I might look for solutions? I sometimes (but not always) get lots of these errors (without changing my code):

[error] ! Fragment evaluation error
[error]     ThrowableException: Could not initialize class code.model.Post$  (FutureTask.java:138)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply$mcZ$sp(PostSpec.scala:68)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)
[error] code.model.PostSpec$$anonfun$1$$anonfun$apply$1.apply(PostSpec.scala:51)

Line 68 of PostSpec is the first line in the (specs2) test that references the Post model companion object:

val test4 = Post.fixJValue(toextract4).extract[Selection]

I'm using Scala 2.9.0-1.

Also: I have no idea whether it matters, but Post is a net.liftweb.mongodb.record.MongoRecord class companion object:

object Post extends Post with MongoMetaRecord[Post] { ... }

1条回答
家丑人穷心不美
2楼-- · 2019-07-26 17:08

In a specs2 specification, Fragments are pieces of the specification. A Fragment can be a Text, an Example, a Step.

Some fragments, like Example and Step are meant to be executed and are supposed to catch Exceptions so that they can be marked as failures. But they won't catch Errors (except AssertionErrors). So if an Example throws an OutOfMemoryError, this will be reported as a Fragment evaluation error.

Other fragments, like Text fragments are not supposed to throw exceptions when being evaluated. If they do, you will get the same Fragment evaluation error message.

Without seeing the full specification it's hard for me to say what's happening there but I suspect that you had a non-Exception type thrown in the body of an Example. But I have more questions than answers for now:

  • where is test4 declared? Inside the specification body? Inside a Context case class?
  • since errors happen intermittently, are you sure you always have a proper mongodb context? Maybe your specification examples are being executed concurrently on the same mongo db instance?
查看更多
登录 后发表回答