darrachequesne / notepack

A fast Node.js implementation of the latest MessagePack spec
MIT License
75 stars 19 forks source link

throw new Error('Could not encode') #29

Closed qiulang closed 1 year ago

qiulang commented 1 year ago

When add socket.io/admin-ui, I hit Error('Could not encode');

const { instrument } = require("@socket.io/admin-ui");
instrument(io, {
  auth: {
    type: "basic",
    username: "xxx",
    password: "xxxxxx"
  },
});
.../node_modules/notepack.io/lib/encode.js:256
      throw new Error('Could not encode');
            ^
Error: Could not encode
    at _encode (.../node_modules/notepack.io/lib/encode.js:256:13)
    at _encode (.../node_modules/notepack.io/lib/encode.js:162:19)
    at _encode (.../node_modules/notepack.io/lib/encode.js:162:19)
    at _encode (.../node_modules/notepack.io/lib/encode.js:246:17)
    at _encode (.../node_modules/notepack.io/lib/encode.js:162:19)
    at Object.encode (.../node_modules/notepack.io/lib/encode.js:261:41)
    at RedisAdapter.broadcast (.../node_modules/socket.io-redis/dist/index.js:313:33)
    at BroadcastOperator.emit (.../node_modules/socket.io/dist/broadcast-operator.js:109:22)
    at Namespace.emit (.../node_modules/socket.io/dist/namespace.js:170:73)
    at Socket.<anonymous> (.../node_modules/@socket.io/admin-ui/dist/index.js:284:36)
darrachequesne commented 1 year ago

@qiulang hi! Could not encode means the encoder encountered something it was not able to encode (for example, a Set). What are you trying to send? Could you please provide an example?

qiulang commented 1 year ago

I found the cause

          socket.emit('login', {...//any data})  // won't crash
          socket.emit('login', {...//any data}, reply => {});  //crash even reply is {}

But why did "@socket.io/admin-ui" cause that problem ?

qiulang commented 1 year ago

@darrachequesne I did not see your reply for some days. Not sure if you find the cause.

So I create a project (based on Socket.IO Fiddle) to reproduce the issue https://github.com/qiulang/socket.io-admin-ui, please take a look

qiulang commented 1 year ago

Fixed by upgraded "@socket.io/admin-ui to 0.5.1 The root cause was explained at https://github.com/socketio/socket.io-admin-ui/issues/54