Skip to content

Commit 0de1b40

Browse files
committed
verify and report invalid options with stack trace
1 parent 3f4e2f8 commit 0de1b40

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

lib/object-mapper.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ function assertValidateOptions(options) {
2626
const ajv = new Ajv({ allErrors: true });
2727
const valid = ajv.validate(optionsSchema, options);
2828
if (!valid) {
29-
throw new Ajv.ValidationError(ajv.errors);
29+
const err = new Error('Invalid options for ObjectMapper');
30+
err.errors = ajv.errors;
31+
throw err;
3032
}
3133
}
3234

test/mapper.spec.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,24 @@ const TruffleConfig = require('@truffle/config');
1313
const deployedAddress = '0x254dffcd3277C0b1660F6d42EFbB754edaBAbC2B';
1414

1515
describe('Mapper', function () {
16-
let mapper;
17-
18-
before(function () {
19-
mapper = new Mapper({
20-
workingDirectory: __dirname,
16+
describe('constructor', function () {
17+
it('rejects invalid options', function () {
18+
chai.expect(() => {
19+
new Mapper({
20+
workingDirectory: {},
21+
});
22+
}).to.throw();
2123
});
2224
});
2325

2426
describe('map', function () {
27+
let mapper;
28+
before(function () {
29+
mapper = new Mapper({
30+
workingDirectory: __dirname,
31+
});
32+
});
33+
2534
it('uses defaults', async function () {
2635
const values = await mapper.map('MetaCoin', deployedAddress);
2736
chai.expect(values).to.have.property('bytes32Example', 'bytes 32 example');

0 commit comments

Comments
 (0)