flyway-play icon indicating copy to clipboard operation
flyway-play copied to clipboard

html views are not shown in Play!-Framework 2.8 with version 7.2.0

Open phwiget opened this issue 3 years ago • 7 comments

We used successfully flyway-play throught a lot of projects written in Play!-Framework versions 2.3 up to 2.6. With the newest version 2.8, th module does not seem to work properly:

  • in dev mode, if there is a migration to be applied, the usual html-view is not shown. Instead, an internal server error is returned as in prod mode. One can fix this by manually navigation to http://localhost:9000/@flyway and applying the script

Is there a way to resolve this?

phwiget avatar Mar 04 '21 17:03 phwiget

If you can get the following information, please let me know.

  • Stack trace of the error
  • The version of Play Framework you are using
  • The version of flyway-play you are using

tototoshi avatar Mar 05 '21 03:03 tototoshi

Play version: 2.8.7 play-flyway-version: 7.2.0

Stacktrace:

[error] c.p.p.m.BugReporter - New error occured: /static/de/app.bf8b0ad0254ee76d5c60.bundle.min.js
Database 'default' needs migration![An SQL script need to be run on your database.]
org.flywaydb.play.Flyways.$anonfun$checkState$1(Flyways.scala:173)
org.flywaydb.play.InvalidDatabaseRevision: Database 'default' needs migration![An SQL script need to be run on your database.]
        at org.flywaydb.play.Flyways.$anonfun$checkState$1(Flyways.scala:173)
        at org.flywaydb.play.Flyways.$anonfun$checkState$1$adapted(Flyways.scala:168)
        at scala.Option.foreach(Option.scala:257)
        at org.flywaydb.play.Flyways.checkState(Flyways.scala:168)
        at org.flywaydb.play.FlywayWebCommand.$anonfun$handleWebCommand$8(FlywayWebCommand.scala:73)
        at org.flywaydb.play.FlywayWebCommand.$anonfun$handleWebCommand$8$adapted(FlywayWebCommand.scala:69)
        at scala.collection.Iterator.foreach(Iterator.scala:937)
        at scala.collection.Iterator.foreach$(Iterator.scala:937)
        at scala.collection.AbstractIterator.foreach(Iterator.scala:1425)
        at scala.collection.IterableLike.foreach(IterableLike.scala:70)

The stacktrace is working as expected. Normally, the custom flyway views are shown. However, in this case, this error is not caught and simply thrown on each request with an HTTP 500. Hence the views are not appearing. With "view", I mean this view here: grafik

phwiget avatar Mar 05 '21 08:03 phwiget

I've tried a combination of Play 2.8.7 and flyway-play 7.2.0. It seems to be working. I have uploaded the code to this repository. https://github.com/tototoshi/flyway-play-issue-119

Is there anything different in the configuration between my sample code and your application?

tototoshi avatar Mar 05 '21 08:03 tototoshi

@phwiget, @tototoshi I had the same problem, turns out it was because of a custom error handler I added as a workaround for https://github.com/playframework/playframework/issues/10486

it is easily reproducible if you add the following error handler:

class AppErrorHandler extends DefaultHttpErrorHandler(sourceMapper = None)

azzzy avatar Mar 23 '21 14:03 azzzy

@azzzy Thanks for the hint. Did not have time yet to further investigate. However, we use indeed custom error handlers, hence this may be the cause.

phwiget avatar Mar 23 '21 15:03 phwiget

@azzzy Thank you for the clue. Now I can reproduce the error as well.

https://github.com/tototoshi/flyway-play-issue-119/commit/f5da44536b2770e74a1df1e514593795e3b6dce7

If it is caused by using a custom error handler, I think changing the settings of the error handler will help. If you use Play's DefaultErrorHandler you need to pass the HttpErrorConfig or environment: Environment & configuration: Configuration properly and set showDevError true.

For example, The code above by @azzzy needs to be like this:

class AppErrorHandler @Inject()(environment: Environment, configuration: Configuration)
  extends DefaultHttpErrorHandler(environment, configuration, sourceMapper = None, router = None)

or

class AppErrorHandler @Inject()(environment: Environment, configuration: Configuration)
  extends DefaultHttpErrorHandler(environment, configuration, sourceMapper = None, router = None)

The below is the source code of the Play framework. It has showDevError=false, probably for security reasons.

https://github.com/playframework/playframework/blob/2.8.7/core/play/src/main/scala/play/api/http/HttpErrorHandler.scala#L122-L159

case class HttpErrorConfig(showDevErrors: Boolean = false, playEditor: Option[String] = None)

/**
 * The default HTTP error handler.
 *
 * This class is intended to be extended, allowing users to reuse some of the functionality provided here.
 *
 * @param router An optional router.
 *               If provided, in dev mode, will be used to display more debug information when a handler can't be found.
 *               This is a lazy parameter, to avoid circular dependency issues, since the router may well depend on
 *               this.
 */
@Singleton
class DefaultHttpErrorHandler(
    config: HttpErrorConfig = HttpErrorConfig(),
    sourceMapper: Option[SourceMapper] = None,
    router: => Option[Router] = None
) extends HttpErrorHandler {
  private val logger = Logger(getClass)

  /**
   * @param environment The environment
   * @param router An optional router.
   *               If provided, in dev mode, will be used to display more debug information when a handler can't be found.
   *               This is a lazy parameter, to avoid circular dependency issues, since the router may well depend on
   *               this.
   */
  def this(
      environment: Environment,
      configuration: Configuration,
      sourceMapper: Option[SourceMapper],
      router: => Option[Router]
  ) =
    this(
      HttpErrorConfig(environment.mode != Mode.Prod, configuration.getOptional[String]("play.editor")),
      sourceMapper,
      router
    )

tototoshi avatar Mar 24 '21 01:03 tototoshi

This should be fixed with Play 2.8.8 (without the need of a custom error handler)

mkurz avatar Apr 26 '21 14:04 mkurz