Skip to content

Better errors #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# fast-json-stringify  [![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify)
# fast-json-stringify

[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](http://standardjs.com/)
[![Build Status](https://travis-ci.org/fastify/fast-json-stringify.svg?branch=master)](https://travis-ci.org/fastify/fast-json-stringify)

__fast-json-stringify__ is x1-4 times faster than `JSON.stringify()`.
It is particularly suited if you are sending small JSON payloads, the
Expand Down Expand Up @@ -297,7 +300,9 @@ const stringify = fastJson(schema, { schema: externalSchema })
<a name="acknowledgements"></a>
## Acknowledgements

This project was kindly sponsored by [nearForm](http://nearform.com).
This project is kindly sponsored by:
- [nearForm](http://nearform.com)
- [LetzDoIt](http://www.letzdoitapp.com/)

<a name="license"></a>
## License
Expand Down
4 changes: 2 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function build (schema, options) {
code = buildArray(schema, code, main, options.schema, schema)
break
default:
throw new Error(`${schema.type} unsupported`)
throw new Error(`${schema.type} unsupported in schema:\n${JSON.stringify(schema, null, 2)}`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we might have our custom error time, and put the schema in a property as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't get you, can you explain it in other words? :)

}

code += `
Expand Down Expand Up @@ -391,7 +391,7 @@ function nested (laterCode, name, key, schema, externalSchema, fullSchema) {
`
break
default:
throw new Error(`${type} unsupported`)
throw new Error(`${type} unsupported in schema:\n${JSON.stringify(fullSchema, null, 2)}`)
}

return {
Expand Down
45 changes: 45 additions & 0 deletions test/type-not-supported.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'

const test = require('tap').test
const build = require('..')

test('type not supported', (t) => {
t.plan(1)

const schema = {
title: 'object with RegExp',
type: 'object',
properties: {
reg: 'string'
}
}

try {
build(schema)
} catch (err) {
t.equal(err.message, `undefined unsupported in schema:\n${JSON.stringify(schema, null, 2)}`)
}
})

test('type not supported - nested', (t) => {
t.plan(1)

const schema = {
title: 'object with RegExp',
type: 'object',
properties: {
key: {
type: 'object',
properties: {
key: 'number'
}
}
}
}

try {
build(schema)
} catch (err) {
t.equal(err.message, `undefined unsupported in schema:\n${JSON.stringify(schema, null, 2)}`)
}
})