mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

writeBook() function seems to be buggy/broken

Open AmeliaYeah opened this issue 1 year ago • 5 comments

  • [x] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.14.0
  • server: vanilla 1.19.3
  • node: 20.7.0

Detailed description of a problem

When utilizing the writeBook API call, an error message seems to pop up that happens regardless of the pages I input. The current code is here:

bot.writeBook(book.slot, extras.format_txt_to_book(txt, is_bedrock)).then(() => {
    //some other stuff that doesnt execute
}).catch((reason) => {
    //this also does not execute, which is strange, because an error message pops up in the console
})

The error message that always pops up is this:

TypeError: Serialization error for play.toServer : SizeOf error for undefined : Cannot read properties of undefined (reading 'length')
    at eval (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:712:39)
    at Object.packet_edit_book (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:717:9)
    at eval (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1259:58)
    at packet (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1299:9)
    at CompiledProtodef.sizeOf (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:89:14)
    at e.message (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:96:40)
    at tryCatch (/home/amelia/mcbot/node_modules/protodef/src/utils.js:50:16)
    at CompiledProtodef.createPacketBuffer (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:96:20)
    at Serializer.createPacketBuffer (/home/amelia/mcbot/node_modules/protodef/src/serializer.js:12:23)
    at Serializer._transform (/home/amelia/mcbot/node_modules/protodef/src/serializer.js:18:18) {
  field: 'play.toServer'
}
TypeError: Serialization error for play.toServer : SizeOf error for undefined : Cannot read properties of undefined (reading 'length')
    at eval (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:712:39)
    at Object.packet_edit_book (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:717:9)
    at eval (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1259:58)
    at packet (eval at compile (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1299:9)
    at CompiledProtodef.sizeOf (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:89:14)
    at e.message (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:96:40)
    at tryCatch (/home/amelia/mcbot/node_modules/protodef/src/utils.js:50:16)
    at CompiledProtodef.createPacketBuffer (/home/amelia/mcbot/node_modules/protodef/src/compiler.js:96:20)
    at Serializer.createPacketBuffer (/home/amelia/mcbot/node_modules/protodef/src/serializer.js:12:23)
    at Serializer._transform (/home/amelia/mcbot/node_modules/protodef/src/serializer.js:18:18) {
  field: 'play.toServer'
}

What did you try yet?

Looking at the error messages, it does not seem to be linked to anything in my code. However, I tried anyway, thinking this may have happened too deep in the code for it to print out. The following is what I have tried, all of which have failed to solve the problem:

  • I put an empty array [] instead of the function, so that it would be writeBook(book.slot, []).
  • I put an array that was not empty but would fit on a normal minecraft book (["abcdefg"])
  • I didn't use book.slot but instead used some other test slot that I knew would be empty during my testing. This produced a more sane error that did go into the catch statement, but it did tell me that I was indeed correct with my usage of book.slot

It is also worth mentioning that it is certain book is an actual item in the inventory, and the pages array is indeed an array of strings.

Expected behavior

I expected for the book to be written and for the code to continue as usual, or for it to atleast enter the catch portion like a normal error.

AmeliaYeah avatar Sep 27 '23 03:09 AmeliaYeah

So I have downgraded to version 1.16 and it appears to work, I suppose this is just an issue with 1.19.3 not being supported yet.

AmeliaYeah avatar Sep 27 '23 14:09 AmeliaYeah

dont leave us hanging

HellishBro avatar Oct 14 '23 04:10 HellishBro

can confirm in 1.20.1

szdytom avatar Nov 01 '23 11:11 szdytom

I have this error on 1.20.2

andreasdc avatar Nov 06 '23 06:11 andreasdc

Tested in 1.20 as well using the provided book.js example verbatim. The bot disconnects and I get the below pasted error in the console.

I'm trying to fill chiseled bookcase library with all of the books from Skyrim, but unfortunately my project is blocked by this. I hope it can be prioritized by the maintainers.

(node:24756) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
logged in
TypeError: Serialization error for play.toServer : SizeOf error for undefined : Cannot read properties of undefined (reading 'length')
    at eval (eval at compile (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:258:12), <anonymous>:756:39)
    at Object.packet_edit_book (eval at compile (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:258:12), <anonymous>:761:9)
    at eval (eval at compile (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1305:58)
    at packet (eval at compile (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:258:12), <anonymous>:1345:9)
    at CompiledProtodef.sizeOf (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:89:14)
    at e.message (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:96:40)
    at tryCatch (/home/user/src/web/mcbots/node_modules/protodef/src/utils.js:50:16)
    at CompiledProtodef.createPacketBuffer (/home/user/src/web/mcbots/node_modules/protodef/src/compiler.js:96:20)
    at Serializer.createPacketBuffer (/home/user/src/web/mcbots/node_modules/protodef/src/serializer.js:12:23)
    at Serializer._transform (/home/user/src/web/mcbots/node_modules/protodef/src/serializer.js:18:18) {
  field: 'play.toServer'
}

mindfilleter avatar Dec 06 '23 06:12 mindfilleter