apiaryio / dredd

Language-agnostic HTTP API Testing Tool
https://dredd.org
MIT License
4.2k stars 280 forks source link

Apiary reporter fails with 'TypeError: Converting circular structure to JSON' #357

Closed ergosarapu closed 7 years ago

ergosarapu commented 8 years ago

Setting transaction fail inside after hook causes the JSON.stringify to throw error when using apiary reporter.

hooks.js:

var hooks = require('hooks');
hooks.after('Questions Collection > List All Questions', function (transaction) {
    transaction.fail = "Fail message";
});

Error and stacktrace:

info: Using apiary reporter.
info: Beginning Dredd testing...
info: Found Hookfiles: hooks.js
fail: GET /questions duration: 419ms
error: GET /questions duration: NaNms
error: TypeError: Converting circular structure to JSON
  at Object.stringify (native)
  at ApiaryReporter._performRequestAsync (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:285:21)
  at ApiaryReporter._performRequestAsync (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:3:57)
  at EventEmitter.<anonymous> (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:140:22)
  at emitTwo (events.js:105:20)
  at EventEmitter.emit (events.js:185:7)
  at TransactionRunner.emitResult (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:363:38)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:390:34
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:147:16
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:154:25
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:248:21
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:97:24
  at TransactionRunner.runHook (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:254:9)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:91:28
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:246:17
  at iterate (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:146:13)
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:162:9)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:389:32
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:147:16
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:142:20)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:388:30
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:590:16
  at proxy (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:18:10)
  at Object.validate (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:60:10)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:549:20
  at proxy (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:18:10)
  at Object.isValid (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:32:10)
  at TransactionRunner.validateTransaction (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:535:18)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:504:30
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:150:14)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:503:28
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:147:16
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:142:20)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at IncomingMessage.<anonymous> (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:502:26)
  at IncomingMessage.g (events.js:273:16)
  at emitNone (events.js:85:20)
  at IncomingMessage.emit (events.js:179:7)
  at endReadableNT (_stream_readable.js:906:12)
  at nextTickCallbackWith2Args (node.js:474:9)
  at process._tickCallback (node.js:388:17)

/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:159
    if ((base = data['resultData']['result'])['general'] == null) {
                                             ^

TypeError: Cannot read property 'general' of undefined
  at EventEmitter.<anonymous> (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/reporters/apiary-reporter.js:159:50)
  at emitTwo (events.js:105:20)
  at EventEmitter.emit (events.js:185:7)
  at TransactionRunner.emitError (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:164:41)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:140:21
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:246:17
  at iterate (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:146:13)
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:162:9)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:389:32
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:147:16
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:142:20)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:388:30
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:590:16
  at proxy (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:18:10)
  at Object.validate (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:60:10)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:549:20
  at proxy (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:18:10)
  at Object.isValid (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/gavel/lib/validate.js:32:10)
  at TransactionRunner.validateTransaction (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:535:18)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:504:30
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:150:14)
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:503:28
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:147:16
  at /Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:251:17
  at async.eachSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:142:20)
  at _asyncMap (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:245:13)
  at Object.mapSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:228:23)
  at Object.async.timesSeries (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/node_modules/async/lib/async.js:1048:22)
  at TransactionRunner.runHooksForData (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:146:20)
  at IncomingMessage.<anonymous> (/Users/ergo/.nvm/versions/node/v5.5.0/lib/node_modules/dredd/lib/transaction-runner.js:502:26)
  at IncomingMessage.g (events.js:273:16)
  at emitNone (events.js:85:20)
  at IncomingMessage.emit (events.js:179:7)
  at endReadableNT (_stream_readable.js:906:12)
  at nextTickCallbackWith2Args (node.js:474:9)
  at process._tickCallback (node.js:388:17)
honzajavorek commented 8 years ago

I was not able to reproduce this. Could you please share a full minimal example or at least the exact command you used, dredd.yml you used, dredd version, etc.?

I see you are using node v5.5.0. I tried it on older version of node, maybe that could be the issue.

honzajavorek commented 8 years ago

Still not able to reproduce, even when using 5.5.0.

ergosarapu commented 8 years ago

I have tried also older versions of node, but the result is same. Here is the current setup:

$ node -v
v5.5.0

$ dredd --version
dredd v1.0.4

I created minimal example with apiary.apib, dredd.yml and hooks.js files. The command I run is simply

$ dredd

I noticed that test results are reported to apiary successfully when setting transaction.fail=true in 'before' hook, so the issue is with 'after' hook.

Below are the contents of files. apiary.apib

FORMAT: 1A

# dredd-test

Hello World API

# Group Hello

## Hello [/message]

### Get Hello [GET]

+ Response 200 (application/json)

        {"hello":"world"}

dredd.yml

reporter: apiary
custom:
  apiaryApiKey: < REMOVED >
  apiaryApiName: dreddtest2
dry-run: null
hookfiles: hooks.js
language: nodejs
sandbox: false
server: null
server-wait: 3
init: false
names: false
only: []
output: []
header: []
sorted: false
user: null
inline-errors: false
details: false
method: []
color: true
level: info
timestamp: false
silent: false
path: []
blueprint: apiary.apib
endpoint: 'http://private-34257-dreddtest2.apiary-mock.com'

hooks.js

var hooks = require('hooks');

hooks.after('Hello > Hello > Get Hello', function (transaction) {
  transaction.fail = "Fail message";
});
honzajavorek commented 8 years ago

I was able to reproduce this! :scream: Thank you @ergosarapu. This minimal example crashes on my computer as you reported. Reproduced on both Node 5 and Node 0.10 (didn't try other versions).

honzajavorek commented 8 years ago

I believe this was fixed in #648. @ergosarapu could you please confirm?

honzajavorek commented 7 years ago

@ergosarapu I didn't hear back, but feel free to re-open should you ever encounter this. Thank you very much for filing this and helping to debug the problem! 👍