ambigious implicits value - twirl form error - forms

With playframework 2.6, I am getting following errors. I have read and found this error only on older versions, that too resolved easily.
[error] /Users/vishalupadhyay/Work/app/views/login_form.scala.html:12:22: ambiguous implicit values:
[error] both method implicitJavaMessages in object PlayMagicForJava of type => play.api.i18n.Messages
[error] and value request of type play.api.mvc.MessagesRequestHeader
[error] match expected type play.api.i18n.MessagesProvider
[error] #helper.inputText(loginForm("password"))
[error] ^
Could not find any answer which can help it. Please see complete code in this link.

Remove the implicit Lang and Messages arguments

Related

How do I post a non-string value in a Scala Http request?

From a Scala program, I need to send values with different primitive types to a Node server.
Http("http://middleware-api:3000/createPromoCodeInCms?")
.postForm
.param("lifetime", 5)
.method("POST")
.asString
This does not compile:
[error] /Users/corbac/Desktop/spark-projects/App.scala:192:24: type mismatch;
[error] found : Int(5)
[error] required: String
[error] .param("lifetime", 5)
[error] ^
However it seems like only strings are accepted as body parameters. Is it possible to post non-string types such as a number or a boolean? If yes how do I do it?
I am using Scala 2.11.

Slick generic query with distinctOn

I would want to make a generic slick query using distinctOn on table to count distinct elements in the column.
def countDistinct(table: TableQuery[_], column: Rep[_]): DBIO[Int] =
table.distinctOn(_ => column).length.result
This code above doesn't compile because:
No matching Shape found.
[error] Slick does not know how to map the given types.
[error] Possible causes: T in Table[T] does not match your * projection,
[error] you use an unsupported type in a Query (e.g. scala List),
[error] or you forgot to import a driver api into scope.
[error] Required level: slick.lifted.FlatShapeLevel
[error] Source type: slick.lifted.Rep[_]
[error] Unpacked type: T
[error] Packed type: Any
[error] table.distinctOn(_ => column).length.result
FlatShapeLevel instead of Rep[_] also doesn't work. I'm using slick 3.
distinctOn doesn't work properly in Slick due to incorrect projection to a particular field/column. The bug was raised 5 years ago, surprisingly still hasn't been resolved.

spark example wont compile

Trying to run one of apache sparks example codes (https://github.com/apache/spark/blob/master/examples/src/main/scala/org/apache/spark/examples/graphx/AggregateMessagesExample.scala) I get the following compile error
too many arguments for method sendToDst: (msg: (Int, Double))Unit
[error] Error occurred in an application involving default arguments.
[error] triplet.sendToDst(1, triplet.srcAttr)
[error] ^
[error] one error found
But looking at the mehtods it seems to be correct. Not sure what is wrong here.
It looks like the method you are calling expects a single argument (a Tuple2) and you are passing in 2 arguments.
Try
triplet.sendToDst((1, triplet.srcAttr))

Problems with stubbing spy'ed object in scala

I have a pretty complex test where I decided to go with approach of partial stubbing of tested class. in my test I have something like this:
val srv = new Service()
val srvSpy = spy(srv)
doReturn(now).when(srvSpy).getRunDateInTimeZone(futureChecklist)
doReturn("boo").when(srvSpy).interpolateChecklistName("name", now)
val returnTuple = (createdChlRev, createdChl)
doReturn(returnTuple).when(srvSpy).create(fChlCreatorId,
fChlCreatorEmail,
"username",
true,
templateId,
"boo",
optDueDate)(connection)
val (chlRev, chl) = srv.createFromFutureChecklist(futureChecklist)(connection)
In the code above, the first two stubbed methods working as expected. However, the last one throws an error:
[error] Tuple2 cannot be returned by create$default$8() [error]
create$default$8() should return JsObject [error] *** [error] If
you're unsure why you're getting above error read on. [error] Due
to the nature of the syntax above problem might occur because: [error]
1. This exception might occur in wrongly written multi-threaded tests. [error] Please refer to Mockito FAQ on limitations of
concurrency testing. [error] 2. A spy is stubbed using
when(spy.foo()).then() syntax. It is safer to stub spies - [error]
- with doReturn|Throw() family of methods. More in javadocs for Mockito.spy() method.
I've trying bunch of different approached of stubbing and still getting the same error. At this point I have no idea even where to look.
What am I doing wrong?
Any advice would be helpful.
Thanks
Sorry, it was my own dumb mistake. I was stubbing the spied class, but calling the original one :(
Thanks,

Why can't _ be used inside of string interpolation?

This works
(x => s"$x")
but this
(s"${_}")
results in
[error] ...: unbound placeholder parameter
[error] (s"${_}")
Is this a case of leaky abstraction?
Furthermore: (s"$_") fails with a completely different output:
[error] ...: invalid string interpolation: `$$', `$'ident or `$'BlockExpr expected
[error] (s"$_")
[error] ^
[error] ...: unclosed string literal
[error] (s"$_")
Calling string interpolation a leaky abstraction is totally right in my opinion. While it works fine in most cases, there are many edge cases where it just doesn't work the way how one expects it. This one is another incarnation of such an edge case.
I don't know why s"$_" is not accepted by the compiler. Some time ago there were a pull request that introduced this syntax for pattern matching: PR 2823
Interestingly this PR also contains test cases that test that the underscore outside of a pattern match produces an error.
Unfortunately there is no further description why this is implemented the way it is implemented.
Som Snytt, the guy who implemented the PR is active on SO, hopefully he can tell more.