promzard
promzard copied to clipboard
promzard.PromZard fires data even when error occurred
Regarding the class promzard.PromZard the docs say:
Emits either a
dataevent with the data, or aerrorevent if it blows up. Iferroris emitted, thendatanever will be.
The following code throws an error in the input file. The result is that both error and data events are emitted.
const fs = require('fs')
const path = require('path')
const { inspect } = require('util')
const { PromZard } = require('promzard')
const inputFile = path.resolve(__dirname, 'input.js')
fs.writeFileSync(inputFile, `throw new Error('Break stuff')`)
const pz = new PromZard(inputFile, {})
pz.on('error', err => console.log('error: ' + err))
pz.on('data', data => console.log('data: ' + inspect(data)))
Output:
error: Error: Break stuff
data: {}
An example for effect in the wild: This bug causes init-package-json to continue wanting to write a file even after an error occurred during processing of the input file. Sample output using the input file from above with init-package-json:
Break stuff
About to write to /tmp/tmp.1uWPpEnFlC/package.json:
{
"name": "",
"version": ""
}
Is this OK? (yes) n
Aborted.