Skip to content

Commit 40b3032

Browse files
committed
Fix implicit messages
1 parent 666371f commit 40b3032

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

rest/src/main/scala/io/udash/rest/raw/RestResponse.scala

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,14 @@ object RestResponse extends RestResponseLowPrio {
5555
}
5656

5757
implicit def taskLikeFromResponseTask[F[_], T](
58-
implicit fromTask: FromTask[F], fromResponse: AsReal[RestResponse, T]
58+
implicit fromTask: FromTask[F],
59+
fromResponse: AsReal[RestResponse, T],
5960
): AsReal[Task[RestResponse], Try[F[T]]] =
6061
rawTask => Success(fromTask.fromTask(rawTask.map(fromResponse.asReal)))
6162

6263
implicit def taskLikeToResponseTask[F[_], T](
63-
implicit taskLike: TaskLike[F], asResponse: AsRaw[RestResponse, T]
64+
implicit taskLike: TaskLike[F],
65+
asResponse: AsRaw[RestResponse, T],
6466
): AsRaw[Task[RestResponse], Try[F[T]]] =
6567
_.fold(Task.raiseError, ft => Task.from(ft).map(asResponse.asRaw)).recoverHttpError
6668

@@ -70,13 +72,13 @@ object RestResponse extends RestResponseLowPrio {
7072
@implicitNotFound("${F}[${T}] is not a valid result type because:\n#{forResponseType}")
7173
implicit def effAsyncAsRealNotFound[F[_], T](implicit
7274
fromAsync: TaskLike[F],
73-
forResponseType: ImplicitNotFound[AsReal[RestResponse, T]]
75+
forResponseType: ImplicitNotFound[AsReal[RestResponse, T]],
7476
): ImplicitNotFound[AsReal[Task[RestResponse], Try[F[T]]]] = ImplicitNotFound()
7577

7678
@implicitNotFound("${F}[${T}] is not a valid result type because:\n#{forResponseType}")
7779
implicit def effAsyncAsRawNotFound[F[_], T](implicit
7880
toAsync: TaskLike[F],
79-
forResponseType: ImplicitNotFound[AsRaw[RestResponse, T]]
81+
forResponseType: ImplicitNotFound[AsRaw[RestResponse, T]],
8082
): ImplicitNotFound[AsRaw[Task[RestResponse], Try[F[T]]]] = ImplicitNotFound()
8183

8284
// following two implicits provide nice error messages when result type of HTTP method is totally wrong
@@ -185,12 +187,14 @@ object StreamedRestResponse extends StreamedRestResponseLowPrio {
185187
}
186188

187189
implicit def taskLikeFromResponseTask[F[_], T](
188-
implicit fromTask: FromTask[F], fromResponse: AsReal[StreamedRestResponse, T]
190+
implicit fromTask: FromTask[F],
191+
fromResponse: AsReal[StreamedRestResponse, T],
189192
): AsReal[Task[StreamedRestResponse], Try[F[T]]] =
190193
rawTask => Success(fromTask.fromTask(rawTask.map(fromResponse.asReal)))
191194

192195
implicit def taskLikeToResponseTask[F[_], T](
193-
implicit taskLike: TaskLike[F], asResponse: AsRaw[StreamedRestResponse, T]
196+
implicit taskLike: TaskLike[F],
197+
asResponse: AsRaw[StreamedRestResponse, T],
194198
): AsRaw[Task[StreamedRestResponse], Try[F[T]]] =
195199
_.fold(Task.raiseError, ft => Task.from(ft).map(asResponse.asRaw)).recoverHttpError
196200

@@ -204,8 +208,8 @@ object StreamedRestResponse extends StreamedRestResponseLowPrio {
204208
): AsRaw[Task[StreamedRestResponse], Try[Observable[T]]] =
205209
_.fold(Task.raiseError, ft => Task.eval(ft).map(asResponse.asRaw)).recoverHttpError
206210

207-
// following two implicits provide nice error messages when serialization is lacking for HTTP method result
208-
// while the async wrapper is fine (e.g. Future)
211+
// following implicits provide nice error messages when serialization is lacking for HTTP method result
212+
// while the async wrapper is fine
209213

210214
@implicitNotFound("${F}[${T}] is not a valid result type because:\n#{forResponseType}")
211215
implicit def effAsyncAsRealNotFound[F[_], T](implicit
@@ -219,6 +223,16 @@ object StreamedRestResponse extends StreamedRestResponseLowPrio {
219223
forResponseType: ImplicitNotFound[AsRaw[StreamedRestResponse, T]]
220224
): ImplicitNotFound[AsRaw[Task[StreamedRestResponse], Try[F[T]]]] = ImplicitNotFound()
221225

226+
@implicitNotFound("Observable[${T}] is not a valid result type because:\n#{forResponseType}")
227+
implicit def observableAsRealNotFound[T](implicit
228+
forResponseType: ImplicitNotFound[AsReal[StreamedBody, Observable[T]]]
229+
): ImplicitNotFound[AsReal[Task[StreamedRestResponse], Try[Observable[T]]]] = ImplicitNotFound()
230+
231+
@implicitNotFound("Observable[${T}] is not a valid result type because:\n#{forResponseType}")
232+
implicit def observableAsRawNotFound[T](implicit
233+
forResponseType: ImplicitNotFound[AsRaw[StreamedBody, Observable[T]]]
234+
): ImplicitNotFound[AsRaw[Task[StreamedRestResponse], Try[Observable[T]]]] = ImplicitNotFound()
235+
222236
// following two implicits provide nice error messages when result type of HTTP method is totally wrong
223237

224238
@implicitNotFound("#{forResponseType}")

rest/src/main/scala/io/udash/rest/raw/StreamedBody.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,12 @@ trait StreamedBodyLowPrio { this: StreamedBody.type =>
9898
implicit def bodyJsonListAsReal[T](implicit jsonAsReal: AsReal[JsonValue, T]): AsReal[StreamedBody, Observable[T]] =
9999
v => StreamedBody.castOrFail[StreamedBody.JsonList](v).elements.map(jsonAsReal.asReal)
100100

101-
@implicitNotFound("Cannot deserialize ${T} from StreamedBody, because:\n#{forJson}")
101+
@implicitNotFound("Cannot deserialize Observable[${T}] from StreamedBody, because:\n#{forJson}")
102102
implicit def asRealNotFound[T](
103103
implicit forJson: ImplicitNotFound[AsReal[JsonValue, T]]
104104
): ImplicitNotFound[AsReal[StreamedBody, Observable[T]]] = ImplicitNotFound()
105105

106-
@implicitNotFound("Cannot serialize ${T} into StreamedBody, because:\n#{forJson}")
106+
@implicitNotFound("Cannot serialize Observable[${T}] into StreamedBody, because:\n#{forJson}")
107107
implicit def asRawNotFound[T](
108108
implicit forJson: ImplicitNotFound[AsRaw[JsonValue, T]]
109109
): ImplicitNotFound[AsRaw[StreamedBody, Observable[T]]] = ImplicitNotFound()

rest/src/test/scala/io/udash/rest/CompilationErrorsTest.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,10 @@ class CompilationErrorsTest extends AnyFunSuite with CompilationErrorAssertions
146146
"""cannot translate between trait MissingObservableSerializerForResult and trait RawRest:
147147
|problem with method streamMeth:
148148
| * it cannot be translated into an HTTP GET method:
149-
| monix.reactive.Observable[Any] is not a valid result type because:
150-
| Cannot serialize monix.reactive.Observable[Any] into RestResponse, because:
151-
| Cannot serialize monix.reactive.Observable[Any] into HttpBody, because:
152-
| Cannot serialize monix.reactive.Observable[Any] into JsonValue, because:
153-
| No GenCodec found for monix.reactive.Observable[Any]
149+
| monix.reactive.Observable[Any] is not a valid result type of HTTP REST method - it must be a Future
154150
| * it cannot be translated into an HTTP GET stream method:
155-
| monix.reactive.Observable[Any] is not a valid result type because:
156-
| Cannot serialize monix.reactive.Observable[Any] into StreamedRestResponse, because:
157-
| Cannot serialize Any into StreamedBody, because:
151+
| Observable[Any] is not a valid result type because:
152+
| Cannot serialize Observable[Any] into StreamedBody, because:
158153
| Cannot serialize Any into JsonValue, because:
159154
| No GenCodec found for Any""".stripMargin)
160155
}
@@ -177,7 +172,7 @@ class CompilationErrorsTest extends AnyFunSuite with CompilationErrorAssertions
177172
| * it cannot be translated into an HTTP GET stream method:
178173
| monix.eval.Task[monix.reactive.Observable[Any]] is not a valid result type because:
179174
| Cannot serialize monix.reactive.Observable[Any] into StreamedRestResponse, because:
180-
| Cannot serialize Any into StreamedBody, because:
175+
| Cannot serialize Observable[Any] into StreamedBody, because:
181176
| Cannot serialize Any into JsonValue, because:
182177
| No GenCodec found for Any""".stripMargin)
183178
}

0 commit comments

Comments
 (0)