Skip to content
This repository has been archived by the owner on Sep 22, 2022. It is now read-only.

'Cannot find type for url' error for items of google.protobuf.Any type #41

Open
pmirek opened this issue May 30, 2022 · 1 comment
Open
Labels
bug Something isn't working

Comments

@pmirek
Copy link

pmirek commented May 30, 2022

Description

How Any type is handled, as I have issues to get it working.
I have offer_item, that is defined as

message OfferItem {
  google.protobuf.Any offer_item = 1;
}

But got errors related to finding class referenced from that item.

Message being sent:

grpcurl -plaintext -import-path ./protos -proto stub/offer/proto/OfferSvc.proto -d '
{
  "offer_id": "newoffer001",
  "ttl": { "seconds": 900 },
  "offer_to_add": {
    "offer_items": [
      {
        "offer_item": {
          "value": "newoffer001",
          "@type": "type.googleapis.com/google.protobuf.StringValue"
        }
      }
    ]
  }
}' localhost:50000 stub.offer.proto.OfferSvc/addOffer

From logs I got:

Message:
offer_id: "newoffer001"
ttl {
  seconds: 900
}
offer_to_add {
  offer_items {
    offer_item {
      type_url: "type.googleapis.com/google.protobuf.StringValue"
      value: "\n\032newoffer001"
    }
  }
}

And exception stack:

Caused by: com.google.protobuf.InvalidProtocolBufferException: Cannot find type for url: type.googleapis.com/google.protobuf.StringValue
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printAny(JsonFormat.java:886) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.access$1000(JsonFormat.java:714) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl$1.print(JsonFormat.java:787) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:766) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1263) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1128) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printField(JsonFormat.java:1052) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:1030) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:769) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1263) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1128) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printRepeatedFieldValue(JsonFormat.java:1066) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printField(JsonFormat.java:1050) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:1030) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:769) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1263) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printSingleFieldValue(JsonFormat.java:1128) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.printField(JsonFormat.java:1052) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:1030) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$PrinterImpl.print(JsonFormat.java:769) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$Printer.appendTo(JsonFormat.java:372) ~[protobuf-java-util-3.19.2.jar:na]
        at com.google.protobuf.util.JsonFormat$Printer.print(JsonFormat.java:382) ~[protobuf-java-util-3.19.2.jar:na]

Though, when on container, it looks like StringValue is there:

/usr/src/java-code/build/classes# find . | grep String
./java/main/com/google/protobuf/StringValueOrBuilder.class
./java/main/com/google/protobuf/StringValue$1.class
./java/main/com/google/protobuf/StringValue$Builder.class
./java/main/com/google/protobuf/StringValue.class

Is this code issue, or I need to make corrections in test set or mock configuration to make it working?

@pmirek pmirek added the bug Something isn't working label May 30, 2022
@pmirek
Copy link
Author

pmirek commented May 31, 2022

Looks like similar issue was here: protocolbuffers/protobuf#6584
and testing from google including Any type for json printing: https://github.com/protocolbuffers/protobuf/blob/main/java/util/src/test/java/com/google/protobuf/util/JsonFormatTest.java

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant