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: undefined is not a function in obj.hasOwnProperty(k) #290

Closed
aaronjensen opened this issue May 30, 2017 · 3 comments
Closed

TypeError: undefined is not a function in obj.hasOwnProperty(k) #290

aaronjensen opened this issue May 30, 2017 · 3 comments

Comments

@aaronjensen
Copy link

querystring objects seem to break rollbar. It may have something to do with nodejs/node#6289

This is the property that is being scrubbed that is causing the failure:

  GET: { color: '999' },

Exception:

/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:129
      if (obj.hasOwnProperty(k)) {
              ^

TypeError: undefined is not a function
    at traverse (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:129:15)
    at scrubber (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:431:16)
    at traverse (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:142:14)
    at scrubber (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:431:16)
    at traverse (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:142:14)
    at Object.scrub (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/utility.js:439:3)
    at Array.scrubPayload (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/server/transforms.js:137:5)
    at cb (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/notifier.js:109:31)
    at Array.addRequestData (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/server/transforms.js:129:3)
    at cb (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/notifier.js:109:31)
    at cb (/Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/server/transforms.js:78:5)
    at /Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/node_modules/async/lib/async.js:49:16
    at /Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/node_modules/async/lib/async.js:263:32
    at /Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/node_modules/async/lib/async.js:40:16
    at /Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/server/transforms.js:162:14
    at /Users/aaronjensen/Source/my-app/functions/node_modules/rollbar/src/server/parser.js:289:12
@brianr
Copy link
Member

brianr commented May 30, 2017

Thanks @aaronjensen - we're looking into this today.

@rokob
Copy link
Contributor

rokob commented May 30, 2017

Object.create(null) ugh; I have a solution, will fix

@rokob rokob closed this as completed in 7eef362 May 30, 2017
rokob added a commit that referenced this issue May 30, 2017
Fixes #290 handle objects without Object in prototype chain
@aaronjensen
Copy link
Author

Thanks for the quick turnaround! Would you mind dropping a note here on the next release so I can upgrade and remove my workaround? Thanks

mudetroit pushed a commit that referenced this issue Mar 14, 2024
Sometimes people use `Object.create(null)` which means that Object does not end up in the prototype
chain of said created objects. This means that hasOwnProperty is not a method on that object so
calling `obj.hasOwnProperty(prop)` will break. To get around this, we can use
`Object.prototype.hasOwnProperty.call(obj, prop)`. As far as I can tell this is safe at least as far
back as IE 6 and all version of node. It is only relevant when we don't really know how the object
was constructed, so it isn't necessary to use this universally. There is a miniscule performance hit
and a bit of a readability issue with it, so prefer not to use this style when we create the object
ourselves.
mudetroit pushed a commit that referenced this issue Mar 14, 2024
Fixes #290 handle objects without Object in prototype chain
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

3 participants