You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2020/03/03 08:10:45 UTC

[GitHub] [openwhisk] markusthoemmes opened a new pull request #4848: Remove explicit right biasing of Eithers.

markusthoemmes opened a new pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848
 
 
   <!--- Provide a concise summary of your changes in the Title -->
   
   ## Description
   Since Scala 2.12, [Either has been right biased](https://www.scala-lang.org/api/2.12.0/scala/util/Either.html) so explicitly calling `.right` before mapping etc is not necessary. Scala 2.13 deprecates this usage so... let's get rid of it now.
   
   This also removes usages of `.right.get` for the same reason and to drop potential error cases where there are none.
   
   No semantic change intended.
   
   ## Related issue and scope
   Ref #4741 
   
   ## Types of changes
   <!--- What types of changes does your code introduce? Use `x` in all the boxes that apply: -->
   - [X] Bug fix (generally a non-breaking change which closes an issue).
   
   ## Checklist:
   <!--- Please review the points below which help you make sure you've covered all aspects of the change you're making. -->
   
   - [X] I signed an [Apache CLA](https://github.com/apache/openwhisk/blob/master/CONTRIBUTING.md).
   - [X] I reviewed the [style guides](https://github.com/apache/openwhisk/wiki/Contributing:-Git-guidelines#code-readiness) and followed the recommendations (Travis CI will check :).
   - [X] I added tests to cover my changes.
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [openwhisk] markusthoemmes commented on a change in pull request #4848: Remove explicit right biasing of Eithers.

Posted by GitBox <gi...@apache.org>.
markusthoemmes commented on a change in pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848#discussion_r386992432
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/Attachments.scala
 ##########
 @@ -66,13 +66,11 @@ object Attachments {
     implicit val serdes = {
       implicit val contentTypeSerdes = new RootJsonFormat[ContentType] {
         override def write(c: ContentType) = JsString(c.value)
-        override def read(js: JsValue) =
-          Try {
-            val JsString(c) = js
-            ContentType.parse(c).right.get
-          } getOrElse {
-            throw new DeserializationException("Could not deserialize content-type")
-          }
+        override def read(js: JsValue) = {
+          Try(js.convertTo[String])
+            .flatMap(ContentType.parse(_).fold(_ => Failure(new Exception("failed to parse content-type")), Success(_)))
 
 Review comment:
   Left doesn't have an exception but a custom error class. To fold everything into a Try, the left needs to be filled with an Exception or we'd need to throw in two places alternatively.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [openwhisk] rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.

Posted by GitBox <gi...@apache.org>.
rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848#discussion_r386986184
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/Attachments.scala
 ##########
 @@ -66,13 +66,11 @@ object Attachments {
     implicit val serdes = {
       implicit val contentTypeSerdes = new RootJsonFormat[ContentType] {
         override def write(c: ContentType) = JsString(c.value)
-        override def read(js: JsValue) =
-          Try {
-            val JsString(c) = js
-            ContentType.parse(c).right.get
-          } getOrElse {
-            throw new DeserializationException("Could not deserialize content-type")
-          }
+        override def read(js: JsValue) = {
+          Try(js.convertTo[String])
+            .flatMap(ContentType.parse(_).fold(_ => Failure(new Exception("failed to parse content-type")), Success(_)))
 
 Review comment:
   could this be further simplified to map to success only? we're not using the exception from left.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [openwhisk] markusthoemmes merged pull request #4848: Remove explicit right biasing of Eithers.

Posted by GitBox <gi...@apache.org>.
markusthoemmes merged pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848
 
 
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

[GitHub] [openwhisk] rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.

Posted by GitBox <gi...@apache.org>.
rabbah commented on a change in pull request #4848: Remove explicit right biasing of Eithers.
URL: https://github.com/apache/openwhisk/pull/4848#discussion_r387009472
 
 

 ##########
 File path: common/scala/src/main/scala/org/apache/openwhisk/core/entity/Attachments.scala
 ##########
 @@ -66,13 +66,11 @@ object Attachments {
     implicit val serdes = {
       implicit val contentTypeSerdes = new RootJsonFormat[ContentType] {
         override def write(c: ContentType) = JsString(c.value)
-        override def read(js: JsValue) =
-          Try {
-            val JsString(c) = js
-            ContentType.parse(c).right.get
-          } getOrElse {
-            throw new DeserializationException("Could not deserialize content-type")
-          }
+        override def read(js: JsValue) = {
+          Try(js.convertTo[String])
+            .flatMap(ContentType.parse(_).fold(_ => Failure(new Exception("failed to parse content-type")), Success(_)))
 
 Review comment:
   thanks - nm then.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services