Forums » Bugs
Lua - pcall() and xpcall() can't trap errors in unspickle()
I recently discovered that `pcall()` and `xpcall()` can't trap and recover from errors caused by `unspickle()`.
If the string passed to `unspickle()` meets certain criteria, it errors out with a message similar to the following, with the string at fault following "constants:"
invalid spickle string. [string "return {{..."]:4864514: main function has more than 65536 constants:
You can use the following code to create a string that will cause `unspickle()` to error.
unspickle(string.rep('{},', 100000))
Interestingly, I've had strings that are much longer than this example work just fine. The main issue is that regardless of when it errors, `pcall()` and `xpcall()` fail to trap the error.
If the string passed to `unspickle()` meets certain criteria, it errors out with a message similar to the following, with the string at fault following "constants:"
invalid spickle string. [string "return {{..."]:4864514: main function has more than 65536 constants:
You can use the following code to create a string that will cause `unspickle()` to error.
unspickle(string.rep('{},', 100000))
Interestingly, I've had strings that are much longer than this example work just fine. The main issue is that regardless of when it errors, `pcall()` and `xpcall()` fail to trap the error.
An optional second argument has been added to unspickle() that is a boolean to tell it to throw errors so they can be caught by x/pcall.
So: unspickle(string,true) will pass any errors to x/pcall.
So: unspickle(string,true) will pass any errors to x/pcall.