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

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

Open
phwiget opened this issue Mar 4, 2021 · 7 comments
Open

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

phwiget opened this issue Mar 4, 2021 · 7 comments

Comments

@phwiget
Copy link

phwiget commented Mar 4, 2021

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 phwiget changed the title module seems not to work in Play!-Framework 2.8 module does not seem to work in Play!-Framework 2.8 Mar 4, 2021
@phwiget phwiget changed the title module does not seem to work in Play!-Framework 2.8 module does not seem to work properly in Play!-Framework 2.8 Mar 4, 2021
@phwiget phwiget changed the title module does not seem to work properly in Play!-Framework 2.8 module does not seem to work properly in Play!-Framework 2.8 with version 7.2.0 Mar 4, 2021
@phwiget phwiget changed the title module does not seem to work properly in Play!-Framework 2.8 with version 7.2.0 html views are not shown in Play!-Framework 2.8 with version 7.2.0 Mar 4, 2021
@tototoshi
Copy link
Member

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

@phwiget
Copy link
Author

phwiget commented Mar 5, 2021

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

@tototoshi
Copy link
Member

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?

@azzzy
Copy link

azzzy commented Mar 23, 2021

@phwiget, @tototoshi
I had the same problem, turns out it was because of a custom error handler I added as a workaround for playframework/playframework#10486

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

class AppErrorHandler extends DefaultHttpErrorHandler(sourceMapper = None)

@phwiget
Copy link
Author

phwiget commented Mar 23, 2021

@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.

tototoshi added a commit to tototoshi/flyway-play-issue-119 that referenced this issue Mar 24, 2021
@tototoshi
Copy link
Member

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

tototoshi/flyway-play-issue-119@f5da445

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
    )

@mkurz
Copy link
Member

mkurz commented Apr 26, 2021

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

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

No branches or pull requests

4 participants