data-point
data-point copied to clipboard
Internal inspect functions are called by util.inspect
Problem description
When request entities fail, and the accumulator contains an inspect property, Node will call that function while executing require('util').inspect. This interferes with the error message that's generated here (and possible in other places):
https://github.com/ViacomInc/data-point/blob/master/packages/data-point/lib/entity-types/entity-request/resolve.js#L167
Suggested solution
Internally, the inspect param should have a different name, so that Node does not call it by mistake. We might also look for a method of ignoring inspect properties when stringifying the accumulator. The solution should not make assumptions about the location of the inspect property (it could appear in params, entityOverrides, or anywhere else in the accumulator).
const DataPoint = require('data-point') const assert = require('assert') const nock = require('nock')
Bug Repro
nock('http://www.example.com')
.get('/')
// This triggers an error
// so that util.inspect will be called
.reply(404, {})
const dataPoint = DataPoint.create({
entities: {
'request:example': {
url: 'http://www.example.com',
params: {
inspect: (acc, data) => {
// This will be included in the error message
return 'ERROR_ERROR_ERROR'
}
}
}
}
})
dataPoint.transform('request:example').catch(error => {
assert.ok(error.message.includes('ERROR_ERROR_ERROR'))
})