bug: setValue
and useState
functions fail for large objects
#2815
Labels
Milestone
setValue
and useState
functions fail for large objects
#2815
Which package is this bug report for? If unsure which one to select, leave blank
@crawlee/core
Issue description
Functions
Actor.setValue
andActor.useState
/crawler.useState
useJSON.stringify
function internally to serialize objects. This function cannot handle very large objects and fails withInvalid string length
error. This error is already caught and re-thrown incrawlee
:crawlee/packages/core/src/storages/key_value_store.ts
Lines 31 to 36 in f912b8b
But it would be better to deal with large objects rather then re-throw the error. There're libraries for big JSON data available, such as:
They're based on stream processing.
The issue can be avoided when using
Actor.setValue
by stringifying the object before passing it to thesetValue
function:But
useState
cannot be used with large objects. It would help if theuseState
function accepted a callback function as a parameter where the serialization of the state object could be customized.Steps to reproduce the error:
obj
JSON.stringify(obj)
- the call should fail withInvalid string length
error.JSON.stringify
can be tested with process.js from js-stringify-examples.Actor.setValue('KEY', obj)
- the call should fail immediately withThe "value" parameter cannot be stringified to JSON
errorActor.useState('STATE', obj)
- this should fail during the persistation of the state object (not immediately after the call)Code sample
Package version
v3.12.1
Node.js version
v22.9.0
Operating system
Tested on both Windows and WSL with Debian distro
Apify platform
I have tested this on the
next
releaseNo response
Other context
No response
The text was updated successfully, but these errors were encountered: