diff --git a/index.js b/index.js index f5059c0..2033ebf 100644 --- a/index.js +++ b/index.js @@ -33,7 +33,9 @@ class RefResolver { getSchema (schemaId, jsonPointer = '#') { const schema = this.#schemas[schemaId] if (schema === undefined) { - throw new Error(`Schema with id "${schemaId}" is not found.`) + throw new Error( + `Cannot resolve ref "${schemaId}${jsonPointer}". Schema with id "${schemaId}" is not found.` + ) } if (schema.anchors[jsonPointer] !== undefined) { return schema.anchors[jsonPointer] diff --git a/test/anchor.test.js b/test/anchor.test.js index 76ff7ef..2af6994 100644 --- a/test/anchor.test.js +++ b/test/anchor.test.js @@ -49,6 +49,8 @@ test('should fail to find a schema using an anchor instead of schema id', () => try { refResolver.getSchema(subSchemaAnchor) } catch (err) { - assert.equal(err.message, 'Schema with id "#subSchemaId" is not found.') + assert.equal( + err.message, 'Cannot resolve ref "#subSchemaId#". Schema with id "#subSchemaId" is not found.' + ) } }) diff --git a/test/get-schema.test.js b/test/get-schema.test.js index 1ef7920..a7849e9 100644 --- a/test/get-schema.test.js +++ b/test/get-schema.test.js @@ -164,7 +164,10 @@ test('root $id has higher priority than a schemaId argument', () => { refResolver.getSchema(schemaIdArgument) assert.fail('should have thrown an error') } catch (err) { - assert.equal(err.message, `Schema with id "${schemaIdArgument}" is not found.`) + assert.equal( + err.message, + `Cannot resolve ref "${schemaIdArgument}#". Schema with id "${schemaIdArgument}" is not found.` + ) } }) @@ -187,7 +190,10 @@ test('should not use a root $id if it is an anchor', () => { refResolver.getSchema(schemaIdProperty) assert.fail('should have thrown an error') } catch (err) { - assert.equal(err.message, `Schema with id "${schemaIdProperty}" is not found.`) + assert.equal( + err.message, + `Cannot resolve ref "${schemaIdProperty}#". Schema with id "${schemaIdProperty}" is not found.` + ) } const resolvedSchema2 = refResolver.getSchema(schemaIdArgument)