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

applyFilter: filter.toLowerCase() fails in some cases #339

Closed
dvic opened this issue Apr 29, 2015 · 8 comments
Closed

applyFilter: filter.toLowerCase() fails in some cases #339

dvic opened this issue Apr 29, 2015 · 8 comments
Milestone

Comments

@dvic
Copy link
Contributor

@dvic dvic commented Apr 29, 2015

I notice that in some cases when response payload logging is turned on, this line gives an error https://github.com/hapijs/good/blob/master/lib/utils.js#L99

Debug: internal, implementation, error 
    TypeError: Object function toString() { [native code] } has no method 'toLowerCase'
    at Object.<anonymous> (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/lib/utils.js:99:90)
    at walker (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:190:22)
    at /Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:208:29
    at Array.forEach (native)
    at forEach (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:298:31)
    at walker (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:203:13)
    at walk (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:226:7)
    at Traverse.forEach (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/node_modules/traverse/index.js:50:18)
    at applyFilter (/Users/damirv/Development/dev/qtheatre/qtheatre/qt-hapi-logging/node_modules/good/lib/utils.js:90:24)

I'm not sure why this is happening, should we add a check on the value of filter to ensure it's a string?

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Apr 29, 2015

Looks like you are trying to pass a function as one of your filter rules. The filtering only supports strings. Can you post what your filter rules are?

@dvic

This comment has been minimized.

Copy link
Contributor Author

@dvic dvic commented Apr 29, 2015

None of this makes any sense to me, here's what I did:

console.log("filterRules", filterRules);
console.log("this.parent", this.parent);
console.log("this.parent.key", this.parent.key);
var newVar = (filterRules[this.key] || filterRules[this.parent.key]);
console.log("newVar", newVar);
var filter = newVar.toLowerCase(); // this is what the original line 99 does

The output?

filterRules { password: 'remove' }
this.parent { node: 
   { ok: [Getter],
     nInserted: [Getter],
     nUpserted: [Getter],
     nMatched: [Getter],
     nModified: [Getter],
     nRemoved: [Getter],
     getUpsertedIds: [Function],
     getUpsertedIdAt: [Function],
     getRawResponse: [Function],
     hasWriteErrors: [Function],
     getWriteErrorCount: [Function],
     getWriteErrorAt: [Function],
     getWriteErrors: [Function],
     getLastOp: [Function],
     getWriteConcernError: [Function],
     toJSON: [Function],
     toString: [Function],
     isOk: [Function] },
  node_: 
   { ok: [Getter],
     nInserted: [Getter],
     nUpserted: [Getter],
     nMatched: [Getter],
     nModified: [Getter],
     nRemoved: [Getter],
     getUpsertedIds: [Function],
     getUpsertedIdAt: [Function],
     getRawResponse: [Function],
     hasWriteErrors: [Function],
     getWriteErrorCount: [Function],
     getWriteErrorAt: [Function],
     getWriteErrors: [Function],
     getLastOp: [Function],
     getWriteConcernError: [Function],
     toJSON: [Function],
     toString: [Function],
     isOk: [Function] },
  path: [],
  parent: undefined,
  parents: [ [Circular] ],
  key: undefined,
  isRoot: true,
  level: 0,
  circular: [Circular],
  update: [Function],
  delete: [Function],
  remove: [Function],
  keys: 
   [ 'ok',
     'nInserted',
     'nUpserted',
     'nMatched',
     'nModified',
     'nRemoved',
     'getUpsertedIds',
     'getUpsertedIdAt',
     'getRawResponse',
     'hasWriteErrors',
     'getWriteErrorCount',
     'getWriteErrorAt',
     'getWriteErrors',
     'getLastOp',
     'getWriteConcernError',
     'toJSON',
     'toString',
     'isOk' ],
  before: [Function],
  after: [Function],
  pre: [Function],
  post: [Function],
  stop: [Function],
  block: [Function],
  isLeaf: false,
  notLeaf: true,
  notRoot: false }
this.parent.key undefined
newVar function toString() { [native code] }

As you can see, newVar is indeed a toString() function! Do you have any idea why (given the other data)?

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Apr 29, 2015

What is data when the function is called?

@dvic

This comment has been minimized.

Copy link
Contributor Author

@dvic dvic commented Apr 29, 2015

It's

data { ok: [Getter],
  nInserted: [Getter],
  nUpserted: [Getter],
  nMatched: [Getter],
  nModified: [Getter],
  nRemoved: [Getter],
  getUpsertedIds: [Function],
  getUpsertedIdAt: [Function],
  getRawResponse: [Function],
  hasWriteErrors: [Function],
  getWriteErrorCount: [Function],
  getWriteErrorAt: [Function],
  getWriteErrors: [Function],
  getLastOp: [Function],
  getWriteConcernError: [Function],
  toJSON: [Function],
  toString: [Function],
  isOk: [Function] }
filterRules { password: 'remove' }
this.parent { node: 
   { ok: [Getter],
     nInserted: [Getter],
     nUpserted: [Getter],
     nMatched: [Getter],
     nModified: [Getter],
     nRemoved: [Getter],
     getUpsertedIds: [Function],
     getUpsertedIdAt: [Function],
     getRawResponse: [Function],
     hasWriteErrors: [Function],
     getWriteErrorCount: [Function],
     getWriteErrorAt: [Function],
     getWriteErrors: [Function],
     getLastOp: [Function],
     getWriteConcernError: [Function],
     toJSON: [Function],
     toString: [Function],
     isOk: [Function] },
  node_: 
   { ok: [Getter],
     nInserted: [Getter],
     nUpserted: [Getter],
     nMatched: [Getter],
     nModified: [Getter],
     nRemoved: [Getter],
     getUpsertedIds: [Function],
     getUpsertedIdAt: [Function],
     getRawResponse: [Function],
     hasWriteErrors: [Function],
     getWriteErrorCount: [Function],
     getWriteErrorAt: [Function],
     getWriteErrors: [Function],
     getLastOp: [Function],
     getWriteConcernError: [Function],
     toJSON: [Function],
     toString: [Function],
     isOk: [Function] },
  path: [],
  parent: undefined,
  parents: [ [Circular] ],
  key: undefined,
  isRoot: true,
  level: 0,
  circular: [Circular],
  update: [Function],
  delete: [Function],
  remove: [Function],
  keys: 
   [ 'ok',
     'nInserted',
     'nUpserted',
     'nMatched',
     'nModified',
     'nRemoved',
     'getUpsertedIds',
     'getUpsertedIdAt',
     'getRawResponse',
     'hasWriteErrors',
     'getWriteErrorCount',
     'getWriteErrorAt',
     'getWriteErrors',
     'getLastOp',
     'getWriteConcernError',
     'toJSON',
     'toString',
     'isOk' ],
  before: [Function],
  after: [Function],
  pre: [Function],
  post: [Function],
  stop: [Function],
  block: [Function],
  isLeaf: false,
  notLeaf: true,
  notRoot: false }
@dvic

This comment has been minimized.

Copy link
Contributor Author

@dvic dvic commented Apr 29, 2015

The weird part is that isRoot: true, I thought that we would not end up in the loop if this was the case? (the change we made from my previous PR).

@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Apr 29, 2015

You are giving me way too much info. I need to see the raw data objects that get passed into applyFilter not once it's been sent into Traverse. They should just be basic JS objects.

@dvic

This comment has been minimized.

Copy link
Contributor Author

@dvic dvic commented Apr 29, 2015

Ah okay, the data object is:

{"ok":1,"writeErrors":[],"writeConcernErrors":[],"nInserted":0,"nUpserted":0,"nMatched":1,"nModified":1,"nRemoved":0,"upserted":[]}

I did the following:

    var applyFilter = function (data) {

        var dataBefore = JSON.stringify(data);

        Traverse(data).forEach(function (value) {

            if (this.isRoot) {
                return;
            }

            if (this.isLeaf) {
                if (filterRules[this.key] || filterRules[this.parent.key]) {

                    var newVar = (filterRules[this.key] || filterRules[this.parent.key]);
                    console.log("newVar", newVar);
                    console.log("dataBefore", dataBefore);
                    var filter = newVar.toLowerCase();
@arb

This comment has been minimized.

Copy link
Contributor

@arb arb commented Apr 29, 2015

Please log on to https://gitter.im/hapijs/hapi and DM me, this isn't getting us anywhere.
Just log the object directly, don't JSON it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.