RED.utils.getObjectProperty expected output

Would there be any reason why this function shouldn't always return undefined if any one of the properties in the chain is undefined?

Example:

var msg = {payload: {bar: 'last call'}};
RED.util.getObjectProperty(msg, 'payload.bar');
//returns 'last call'

RED.util.getObjectProperty(msg, 'payload.foo');
//returns undefined

RED.util.getObjectProperty(msg, 'payload.foo.bar');
//results in Uncaught TypeError: Cannot read property 'bar' of undefined

I would think it would be better that it simply returns undefined if you mess up at any point in the chain.

I'm getting ready to send a PR, but wanted to check here first.

Sorry! disregard. I just found the PR already asking about this.

Link ? ( to cross ref)

At first I was not seeing why this shouldn't be fixed, but now I'm thinking that it's nice to be able to differentiate between the child property not existing and one of the parent properties not existing. Maybe returning something other than undefined but maybe the best solution is just to catch the error and work it case by case.

Thanks for listening...

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.