Here's a slightly simplified (but same logic) copy of that area of the function that can be ran in browser console:
function formatValue(ctx, value) {
if (ctx.customInspect &&
value != null &&
typeof value === 'function' &&
!(value.constructor && value.constructor.prototype === value)
) { value.inspect(); }
}
// call the formatter with a function passed in
formatValue({customInspect:true}, () => {}); // throws error b/c value.inspect is not defined
I think it can be easily fixed by just checking that value.inspect is a function:
function formatValue(ctx, value) {
if (ctx.customInspect &&
value != null &&
typeof value === 'function' &&
typeof value.inspect === 'function' &&
!(value.constructor && value.constructor.prototype === value)
) { value.inspect(); }
}
// call the formatter with a function passed in
formatValue({customInspect:true}, () => {}); // throws no error b/c it did not attempt to call value.inspect
Additional context
We ran into this while logging a class that has functions on it using the default pretty logger. We didn't realize it would recurse through all fields and presume that any functions it comes across will have this inspect function.
Describe the bug
util.inspect.polyfill.ts
presumes that any function given to it has aninspect
method:https://github.com/fullstack-build/tslog/blob/master/src/runtime/browser/util.inspect.polyfil.ts#L154-L164
To Reproduce
Here's a slightly simplified (but same logic) copy of that area of the function that can be ran in browser console:
I think it can be easily fixed by just checking that
value.inspect
is a function:Additional context We ran into this while logging a class that has functions on it using the default pretty logger. We didn't realize it would recurse through all fields and presume that any functions it comes across will have this
inspect
function.tslog version 4.7.2