Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any type usage help #110

Open
gkyildirim opened this issue Mar 25, 2024 · 2 comments
Open

Any type usage help #110

gkyildirim opened this issue Mar 25, 2024 · 2 comments

Comments

@gkyildirim
Copy link

gkyildirim commented Mar 25, 2024

I am trying to figure out how to use Any type. I could not find an example nor my primitve attempts to define provider in appl.module.ts (with the help of Copilot) succeed.

May I ask how to use Any type?

If I do not define anything in app.module.ts I have this error:

core.mjs:8506 ERROR Error: Uncaught (in promise): Error: Message pool is required to cast Any to JSON
Error: Message pool is required to cast Any to JSON
    at Any.toProtobufJSON (ngx-grpc-well-known-types.mjs:123:19)
    at DatasetProperty.toProtobufJSON (dataset.pb.ts:5295:41)
    at DatasetProperties.toProtobufJSON (dataset.pb.ts:2860:50)
    at Dataset.toProtobufJSON (dataset.pb.ts:362:27)
    at Pool.toProtobufJSON (pool.pb.ts:586:28)
    at rpc-defs.pb.ts:450:44
    at Array.map (<anonymous>)
    at PoolsResponse.toProtobufJSON (rpc-defs.pb.ts:450:33)
    at Object.responseMapper (app.module.ts:60:51)
    at Object.next (ngx-grpc-core.mjs:189:62)
    at resolvePromise (zone.js:1214:31)
    at resolvePromise (zone.js:1168:17)
    at zone.js:1281:17
    at _ZoneDelegate.invokeTask (zone.js:409:31)
    at core.mjs:23999:55
    at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:23999:36)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Object.onInvokeTask (core.mjs:24300:33)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Zone.runTask (zone.js:178:47)

If I define something like this in app.modules.ts

 export function grpcMessagePoolFactory() {
 const messagePool = new GrpcMessagePool([]);
 messagePool.add([BoolValue, UInt64Value, FloatValue, StringValue, Timestamp]);
 return messagePool;
}

@NgModule({
 providers: [{ provide: GrpcMessagePool, useFactory: grpcMessagePoolFactory }],

I have this error:

core.mjs:8506 ERROR Error: Uncaught (in promise): Error: Message pool is required to cast Any to JSON
Error: Message pool is required to cast Any to JSON
    at Any.toProtobufJSON (ngx-grpc-well-known-types.mjs:123:19)
    at DatasetProperty.toProtobufJSON (dataset.pb.ts:5295:41)
    at DatasetProperties.toProtobufJSON (dataset.pb.ts:2860:50)
    at Dataset.toProtobufJSON (dataset.pb.ts:362:27)
    at Pool.toProtobufJSON (pool.pb.ts:586:28)
    at rpc-defs.pb.ts:450:44
    at Array.map (<anonymous>)
    at PoolsResponse.toProtobufJSON (rpc-defs.pb.ts:450:33)
    at Object.responseMapper (app.module.ts:86:51)
    at Object.next (ngx-grpc-core.mjs:189:62)
    at resolvePromise (zone.js:1214:31)
    at resolvePromise (zone.js:1168:17)
    at zone.js:1281:17
    at _ZoneDelegate.invokeTask (zone.js:409:31)
    at core.mjs:23999:55
    at AsyncStackTaggingZoneSpec.onInvokeTask (core.mjs:23999:36)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Object.onInvokeTask (core.mjs:24300:33)
    at _ZoneDelegate.invokeTask (zone.js:408:60)
    at Zone.runTask (zone.js:178:47)
    ```

My angular version is 15.1 if it matters.

@gkyildirim
Copy link
Author

Hello,

I apologize if I am asking the wrong question at the wrong place.

Thanks for the hard work.

@smnbbrv
Copy link
Owner

smnbbrv commented Apr 5, 2024

Hi, you get this error because some of your code attempts to cast the message that contains Any to JSON.

You would need to adapt this code to pass message pool as a parameter to this method.

The most common reason is you use the standard logger that attempts to cast to JSON.

Try to disable the logger and check if the error is gone or adapt the place where you call toProtobufJSON method

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants