promzard icon indicating copy to clipboard operation
promzard copied to clipboard

promzard.PromZard fires data even when error occurred

Open raphinesse opened this issue 6 years ago • 0 comments

Regarding the class promzard.PromZard the docs say:

Emits either a data event with the data, or a error event if it blows up. If error is emitted, then data never 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.

raphinesse avatar Apr 15 '19 01:04 raphinesse