Skip to content

Commit

Permalink
Improved error messaging
Browse files Browse the repository at this point in the history
  • Loading branch information
JazzBrown1 committed Sep 7, 2020
1 parent bdb099a commit cdce302
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# EZ-Options

Complex Options Objects made easy.
Complex Options Objects made easy with built input checking and meaningful detailed Errors.

![NPM](https://img.shields.io/github/last-commit/JazzBrown1/options)
![NPM](https://img.shields.io/npm/v/ez-options)
Expand Down Expand Up @@ -135,6 +135,17 @@ const claInflated = inflate(claFlat);
options.merge(config, claInflated);
```

### Die Hard Mode

Error checking is turned off in dieHard mode to significantly improve performance in production environments.

You may want to enable this when NODE_ENV is set to 'production'.

~~~javascript
const isProd = Boolean(process.env.NODE_ENV === 'production');
const options = new Options(schema, { dieHard: isProd });
~~~

<a name="bugs"></a>

## Issues
Expand Down
18 changes: 9 additions & 9 deletions src/errors/errorMessages.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,28 @@ import { getType } from '../getType';
export default (option, input, path, type) => {
switch (type) {
case 'PropEnum':
return `Failed to parse property ${path.join('.')}, must be one of the following values: ${option.enum.toString()}`;
return `Failed to merge property: ${path.join('.')}, must be one of the following values: ${option.enum.toString()}`;
case 'PropType':
return `Failed to parse property ${path.join('.')}, is of type: ${getType(input)}, must be one of the following types: ${option.types.toString()}`;
return `Failed to merge property: ${path.join('.')}, is of type: '${getType(input)}', must be one of the following types: ${option.types.toString()}`;
case 'PropChecker':
return `Failed to parse property ${path.join('.')}, checker failed please check it meets requirements`;
return `Failed to merge property: ${path.join('.')}, checker failed please check it meets the requirements`;
case 'ParentType':
return `${path.join('.')} is a parent expected type: Object instead received type: ${getType(input)}`;
return `${path.join('.')} is a parent expected type: 'object' instead received type: '${getType(input)}'`;
case 'UnknownProp':
return `Option property ${path.join('.')} is unknown`;
case 'MergeType':
return '[Options].merge() inputs must be objects';
case 'BuildType':
return 'Options.build() input must be an object';
case 'SchemaObject':
return `Unable to parse schema object ${path.join('.')}, it should be an Object that contains a _parent or _property prop`;
return `Failed to parse schema object: ${path.join('.')}, it should be an Object that contains a _parent or _property prop`;
case 'SchemaTypes':
return `Unable to parse schema object ${path.join('.')}, types should be of type: array but is of type ${getType(option.types)}`;
return `Failed to parse schema object: ${path.join('.')}, types should be of type: 'array' but is of type '${getType(option.types)}'`;
case 'SchemaEnum':
return `Unable to parse schema object ${path.join('.')}, enum should be of type: array but is of type ${getType(option.enum)}`;
return `Failed to parse schema object: ${path.join('.')}, enum should be of type: 'array' but is of type '${getType(option.enum)}'`;
case 'SchemaChecker':
return `Unable to parse schema object ${path.join('.')}, enum should be of type: array but is of type ${getType(option.enum)}`;
return `Failed to parse schema object: ${path.join('.')}, checker should be of type: 'function' but is of type '${getType(option.checker)}'`;
case 'SchemaDefault':
return `Unable to parse schema object ${path.join('.')}, the default value does not parse`;
return `Failed to parse schema object: ${path.join('.')}, the default value is invalid`;
}
};
1 change: 0 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import merge from './merge';
import build from './build';
import { flatMap } from './flatMap';
import { inflate } from './inflate';

const Options = function (schema, ops = {}) {
build(schema, ops.dieHard || ops.dieHardBuild, this);
Expand Down

0 comments on commit cdce302

Please sign in to comment.