Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Invalid value used as weak map key #15

Open
jperelli opened this issue Oct 25, 2017 · 7 comments
Open

TypeError: Invalid value used as weak map key #15

jperelli opened this issue Oct 25, 2017 · 7 comments

Comments

@jperelli
Copy link

No idea why, but I was getting this error. Do you know if I'm using some sort of wrong value as a key in object?

ERROR RETURNED TO CLIENT: TypeError: Invalid value used as weak map key
at WeakMap.set (native)
at mapObj (/home/jperelli/celerative/wysh/WYSHAPI/node_modules/map-obj/index.js:23:7)
at module.exports (/home/jperelli/celerative/wysh/WYSHAPI/node_modules/camelcase-keys/index.js:16:9)
at /home/jperelli/celerative/wysh/WYSHAPI/.webpack/service/app/requests/list.js:560:50
at Array.map (native)
at /home/jperelli/celerative/wysh/WYSHAPI/.webpack/service/app/requests/list.js:555:21
at process._tickDomainCallback (internal/process/next_tick.js:129:7)

@sindresorhus
Copy link
Owner

You're probably giving camelCaseKeys() a non-object.

@eliperkins
Copy link
Sponsor

eliperkins commented Nov 2, 2017

This seems to be related to passing null to camelcaseKeys: https://runkit.com/eliperkins/59fb77dad46b990011223dbb

Should an isObject or input != null check get placed inside this library or do you think this should be left to the caller? I can open a PR to add a check, if so, but I feel like this might be overstepping the boundaries of this library.

@robwierzbowski
Copy link

I think it's best left to the caller. The docs specify input type Object; handling any other type of input gracefully feels like defensive coding which tends to bloat a project.

@jperelli
Copy link
Author

I would argue that the error description gives no clue on how to fix this, so in this particular case it would be good to add an if to camelcase-keys lib

@cinderblock
Copy link

cinderblock commented Nov 23, 2018

Instead of throwing an error, I think it would be better to just pass though invalid arguments.

Edit: sindresorhus/map-obj#15 would fix this ;)

@rameshrr
Copy link

rameshrr commented Jan 8, 2019

Did you try the option deep: true

do not handle nested objects/arrays yourself, let the lib do it,
eg., camelcaseKeys(data, { deep: true });

@cinderblock
Copy link

@rameshrr That only works if the top level data is an object.

camelcaseKeys(true, {deep: true}) throws.

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

No branches or pull requests

6 participants