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

Exception during macro expansion: StackOverflowError #140

Open
bennythomps opened this issue Jan 27, 2017 · 3 comments
Open

Exception during macro expansion: StackOverflowError #140

bennythomps opened this issue Jan 27, 2017 · 3 comments

Comments

@bennythomps
Copy link

Making some basic calls, I'm getting exceptions when I compile:

[error] ApiKey.scala:19: exception during macro expansion: java.lang.StackOverflowError
[error]   def create: (ApiKey) => Future[ApiKey] = withSchema {
[error]                                                       ^
{
  import _root_.troy.driver.InternalDsl._;
  import _root_.troy.driver.codecs.PrimitivesCodecs._;
  val prepared = implicitly[com.datastax.driver.core.Session].prepare("\n            SELECT api_key, name, active\n            FROM api.api_keys\n            WHERE api_key = ?\n        ");
  ((apiKey: java.util.UUID) => {
    def parser(row: _root_.com.datastax.driver.core.Row) = ApiKey(column[java.util.UUID](0)(row).as[CDT.Uuid], column[String](1)(row).as[CDT.Text], column[Boolean](2)(row).as[CDT.Boolean]);
    bind(prepared, param(apiKey).as[CDT.Uuid]).executeAsync(ApiKeyRecord.this.session, scala.concurrent.ExecutionContext.Implicits.global).oneOption(scala.concurrent.ExecutionContext.Implicits.global).parseAs(parser)
  })
}

Here's my schema:

CREATE KEYSPACE api WITH replication = {'class': 'SimpleStrategy' , 'replication_factor': '1'};

CREATE TABLE api.api_keys (
  api_key uuid,
  name text,
  active boolean,
  PRIMARY KEY (api_key)
);

Here's my calling code that's "breaking"

class ApiTokenRecord(implicit session: Session) {

  def create = withSchema { (token: UUID, apiKey: UUID, email: String, expiration: DateTime) =>
    cql"""
      INSERT INTO kiko.api_tokens (api_token, api_key, email, expiration_time)
      VALUES ($token, $apiKey, $email, $expiration)
      """.prepared.executeAsync.map(_ => true)
  }
}

Am I doing something wrong?

@tabdulradi
Copy link
Member

Hello @bennythomps,

Thanks for reporting this bug.
It is .map(_ => true) that triggered it. A workaround (for now) is to rewrite your example like the following:

class ApiTokenRecord(implicit session: Session) {
  def createStatement = withSchema { (token: UUID, apiKey: UUID, email: String, expiration: DateTime) =>
    cql"""
      INSERT INTO api.api_keys (api_token, api_key, email, expiration_time)
      VALUES ($token, $apiKey, $email, $expiration)
      """.prepared.executeAsync
  }
  def create(token: UUID, apiKey: UUID, email: String, expiration: DateTime) =
    createStatement(token, apiKey, email, expiration).map(_ => true)
}

I'll mark this as bug for now. We are currently replacing the current macro implementation with a cleaner one using Scala meta. So hopefully this bug should vanish soon.

@bennythomps
Copy link
Author

Thanks @tabdulradi! What about the .map(_ => true) is breaking it? It's not the permanent solution for me, so what to avoid when shifting will help avoid the problem until the meta stuff is available.

@tabdulradi
Copy link
Member

In general avoid writing arbitrary code inside withSchema block. We only tested for specific cases, like setConsistencyLevel, the current Tree transformation code is not robust.

For the specific case of .map with a lambda, even if the transformation got fixed, still won't work due to a bug in Macros.

You can have a peek on the new scala.meta based implementation here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants