File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed
compiler-plugin/src/main/scala/scalapb/compiler Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -228,9 +228,23 @@ private[compiler] class ParseFromGenerator(
228228 val r = (0 until (requiredFieldMap.size + 63 ) / 64 )
229229 .map(i => s " __requiredFields $i != 0L " )
230230 .mkString(" || " )
231- p.add(
232- s """ if ( ${r}) { throw new _root_.com.google.protobuf.InvalidProtocolBufferException("Message missing required fields.") } """
233- )
231+ p.add(s """ if ( ${r}) { """ )
232+ .indent
233+ .add(" val __missingFields = Seq.newBuilder[_root_.scala.Predef.String]" )
234+ .print(requiredFieldMap.toSeq.sortBy(_._2)) {
235+ case (p, (fieldDescriptor, fieldNumber)) =>
236+ val bitmask = s " 0x ${" %x" .format(1L << fieldNumber)}L "
237+ val fieldVariable = s " __requiredFields ${fieldNumber / 64 }"
238+ p.add(
239+ s """ if (( $fieldVariable & $bitmask) != 0L) __missingFields += " ${fieldDescriptor.scalaName}" """
240+ )
241+ }
242+ .add(
243+ s """ val __message = s"Message missing required fields: $$ {__missingFields.result.mkString(", ")}" """ ,
244+ s """ throw new _root_.com.google.protobuf.InvalidProtocolBufferException(__message) """
245+ )
246+ .outdent
247+ .add(" }" )
234248 }
235249 .add(s " $myFullScalaName( " )
236250 .indented(
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class NoBoxSpec extends AnyFlatSpec with Matchers {
3636 " RequiredCar" should " fail validation if required field is missing" in {
3737 intercept[InvalidProtocolBufferException ] {
3838 RequiredCar .parseFrom(Array .empty[Byte ])
39- }.getMessage must be(" Message missing required fields. " )
39+ }.getMessage must be(" Message missing required fields: tyre1 " )
4040 }
4141
4242 " RequiredCar" should " fail parsing from text if field is empty" in {
You can’t perform that action at this time.
0 commit comments