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(
228
228
val r = (0 until (requiredFieldMap.size + 63 ) / 64 )
229
229
.map(i => s " __requiredFields $i != 0L " )
230
230
.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(" }" )
234
248
}
235
249
.add(s " $myFullScalaName( " )
236
250
.indented(
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ class NoBoxSpec extends AnyFlatSpec with Matchers {
36
36
" RequiredCar" should " fail validation if required field is missing" in {
37
37
intercept[InvalidProtocolBufferException ] {
38
38
RequiredCar .parseFrom(Array .empty[Byte ])
39
- }.getMessage must be(" Message missing required fields. " )
39
+ }.getMessage must be(" Message missing required fields: tyre1 " )
40
40
}
41
41
42
42
" RequiredCar" should " fail parsing from text if field is empty" in {
You can’t perform that action at this time.
0 commit comments