cbor-x icon indicating copy to clipboard operation
cbor-x copied to clipboard

Error: Unknown type function

Open icebob opened this issue 3 years ago • 5 comments

Hi again,

There is a strange error when I'm using CBOR. But the error is not consistent and I can't reproduce it in my env, only on Github Actions CI. Do you have an idea what does Unknown type function mean?

[2021-05-18T18:03:23.335Z] WARN  node2/TRANSPORTER: Invalid incoming GOSSIP_REQ packet. Error: Unknown type function
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1188:11)
    at /home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1224:6
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1096:7)
    at /home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1224:6
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1096:7)
    at /home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1224:6
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1096:7)
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1105:8)
    at /home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1224:6
    at encode (/home/runner/work/moleculer/moleculer/node_modules/cbor-x/dist/node.cjs:1096:7)

I'm trying to isolate the problem and get more information.

icebob avatar May 18 '21 18:05 icebob

It means that an object that is being serialized included an enumerable property that has a method/function value. Do you suppose that maybe an assertion library could be adding properties/methods to the objects?

kriszyp avatar May 18 '21 18:05 kriszyp

I am certainly open to suggestions for how to handle function values (could alternately serialize to a string, or undefined, maybe driven by an option/flag).

kriszyp avatar May 18 '21 19:05 kriszyp

Ahh, then I check the payload properties why it contains Function.

By the way, I suggest just simply skip the Function as other serializers do. Besides CBOR, I'm testing MsgPack, Notepack, Protobuf, Avro, Thrift serializers as well, and all of them just skip the functions.

icebob avatar May 18 '21 19:05 icebob

By the way, you are right, sometimes the payload contains handler functions.

image

icebob avatar May 18 '21 19:05 icebob