notxcain / aecor

Pure functional event sourcing runtime
aecor.io
MIT License
323 stars 34 forks source link

@boopickleWireProtocol macro expansion error due to empty parameter list in event sourced entity api #68

Open SemanticBeeng opened 5 years ago

SemanticBeeng commented 5 years ago

@notxcain I am getting this as soon as I add a method in my event sourced entity api returning *Status. The *Status is implemented similar to BookingStatus from @vpavkin 's tutorial.

The only thing I can see different is that my *Status is in a different sbt module than the entity. But also tried moving it to same sbt module and getting same

Any idea of what might cause this? Not likely this to be an aecor bug but maybe others will run into it so worth having it here.

[error] <macro>:2:4: exception during macro expansion: 
[error] org.scalameta.invariants.InvariantFailedException: invariant failed:
[error] when verifying args.length.>(1).||(args.length.==(1).&&(scala.meta.classifiers.`package`.XtensionClassifiable[scala.meta.Term](args.head)(scala.meta.Tree.classifiable[scala.meta.Term]).is[scala.meta.internal.ast.Quasi](scala.meta.internal.ast.Quasi.ClassifierClass[scala.meta.Term])))
[error] found that args.length.>(1) is false
[error] and also scala.meta.classifiers.`package`.XtensionClassifiable[scala.meta.Term](args.head)(scala.meta.Tree.classifiable[scala.meta.Term]).is[scala.meta.internal.ast.Quasi](scala.meta.internal.ast.Quasi.ClassifierClass[scala.meta.Term]) is false
[error] where args = List("status")
[error]     at org.scalameta.invariants.InvariantFailedException$.raise(Exceptions.scala:15)
[error]     at scala.meta.Term$Tuple$.internal$44(Trees.scala:78)
[error]     at scala.meta.Term$Tuple$.apply(Trees.scala:75)
[error]     at aecor.macros.BoopickleWireProtocolMacro$.$anonfun$apply$4(boopickleWireProtocol.scala:60)
[error]     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
[error]     at scala.collection.immutable.List.foreach(List.scala:389)
[error]     at scala.collection.TraversableLike.map(TraversableLike.scala:234)
[error]     at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
[error]     at scala.collection.immutable.List.map(List.scala:295)
[error]     at aecor.macros.BoopickleWireProtocolMacro$.apply(boopickleWireProtocol.scala:58)
[error]     at aecor.macros.boopickleWireProtocol$inline$.apply(boopickleWireProtocol.scala:16)
[error]   @boopickleWireProtocol trait Session[F[_]] {
vpavkin commented 5 years ago

@SemanticBeeng Hi. Could you pls post source file that causes the error?

vpavkin commented 5 years ago

Ok, DM exchanged showed that the problem is with methods shaped the following way (with an empty param list:

def status(): F[Unit)

Quick workaround is to remove the parens. I'll try to tune the macro to handle this case properly.

@SemanticBeeng Could you please alter the ticket title (I can't)?

SemanticBeeng commented 5 years ago

Vladimir advised the macro crash is due to the empty parameter list in def status() : below. Fixed to make it like def expiresIn :

  def expiresIn: F[com.kse.shared.domain.TimeMs]

  def keepAlive(period: com.kse.shared.domain.TimeMs): F[Unit]

  def status(): F[domain.SessionStatus]

  def terminate(reason: String): F[Unit]
}

Will keep it open to fix this rough edge of the macro. Many thanks.

notxcain commented 5 years ago

Actually I’d rather forbid empty params list methods at all :) They are used to mark something impure, which should not be a case.

SemanticBeeng commented 5 years ago

I would be perfectly okay to close, ofc. A nicer error message would have helped but not sure if the job of the macro is to be aware of event sourced entity design style.

vpavkin commented 5 years ago

It's more about code-style that communicates purity. Aecor calls itself opinionated, so I see no problem with a readable, opinionated error-message.

notxcain commented 5 years ago

A nice error message would be great.