Skip to content

Commit 790d256

Browse files
committed
Merge branch 'master' of github.com:fastify/fast-json-stringify
2 parents 7ada687 + c3994b4 commit 790d256

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -934,7 +934,12 @@ function loadUglify () {
934934
function isValidSchema (schema, externalSchema) {
935935
if (externalSchema) {
936936
Object.keys(externalSchema).forEach(key => {
937-
ajv.addSchema(externalSchema[key], key)
937+
try {
938+
ajv.addSchema(externalSchema[key], key)
939+
} catch (err) {
940+
err.message = '"' + key + '" ' + err.message
941+
throw err
942+
}
938943
})
939944
}
940945
ajv.compile(schema)

test/invalidSchema.test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
'use strict'
2+
3+
const test = require('tap').test
4+
const build = require('..')
5+
6+
// Covers issue #139
7+
test('Should throw on invalid schema', t => {
8+
t.plan(2)
9+
try {
10+
build({}, {
11+
schema: {
12+
invalid: {
13+
type: 'Dinosaur'
14+
}
15+
}
16+
})
17+
t.fail('should be an invalid schema')
18+
} catch (err) {
19+
t.match(err.message, /^"invalid" schema is invalid:.*/, 'Schema contains invalid key')
20+
t.ok(err)
21+
}
22+
})

0 commit comments

Comments
 (0)