Skip to content

Conversation

@iushakov-om
Copy link

There is an issue with trying to set a value to the storage if you do it NOT in request handlers.
For example, this code will work fine:

import scls from 'simple-continuation-local-storage';

const handler = (req, res) => {
    scls.$init();
    scls.foo = 'bar';
}

http.createServer(handler).listen(7777);

But this code will throw an error:

import scls from 'simple-continuation-local-storage';

scls.$init();
scls.foo = 'bar';

The error:

TypeError: 'set' on proxy: trap returned falsish for property 'foo'

This happens because Proxy's 'set' returns false because 'current' is null at that moment.

To fix this I've changed the default value of 'current" from null to an empty object.
My concern is that this change alters the logic in a couple of places...

What do you think, @mike_talbot?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant