bbc/consumer-contracts

Test fails on an empty contract

Closed this issue · 1 comments

tao commented

I've set up two files projects-api.js and sites-api.js, if I run consumer-contracts run with the example in both of these files it works fine.

As soon as I removed the example code from one file and leave just the headers then as error appears:

// projects-api.js
var Contract = require('consumer-contracts').Contract;
var Joi = require('consumer-contracts').Joi;

The failing error on the empty file was as follows:

/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/async.js:61
        fn = function () { throw arg; };
                           ^

TypeError: contract.validate is not a function
    at validateContract (/usr/local/lib/node_modules/consumer-contracts/lib/validator.js:4:12)
    at /usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:1105:9
    at replenish (/usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:982:17)
    at /usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:986:9
    at _asyncMap (/usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:1103:5)
    at /usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:1189:16
    at Object.mapSeries (/usr/local/lib/node_modules/consumer-contracts/node_modules/async/dist/async.js:1016:16)
    at module.exports (/usr/local/lib/node_modules/consumer-contracts/lib/validator.js:13:9)
    at validateFiles (/usr/local/lib/node_modules/consumer-contracts/lib/runner.js:19:3)
    at /usr/local/lib/node_modules/consumer-contracts/lib/runner.js:64:7
    at tryCatcher (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/util.js:16:23)
    at Promise.successAdapter [as _fulfillmentHandler0] (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/nodeify.js:23:30)
    at Promise._settlePromise (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/promise.js:566:21)
    at Promise._settlePromise0 (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/usr/local/lib/node_modules/consumer-contracts/node_modules/bluebird/js/release/promise.js:638:18)

Would you be able to add a warning message that states that an empty file is the problem, or ignore a file with no contracts?

@tao - Thanks for raising this issue. I don't see this as a high priority but I agree that error handling could be improved. I will address this in the next release - will keep you posted.