Skip to content

Commit

Permalink
validation: Improve validation error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Jannis Pohlmann committed Oct 11, 2018
1 parent 130e2d4 commit 54d5452
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ const typeName = value =>
* Converts an immutable or plain JavaScript value to a YAML string.
*/
const toYAML = x =>
yaml.safeDump(typeName(x) === 'list' || typeName(x) === 'map' ? x.toJS() : x, {
indent: 2,
})
yaml
.safeDump(typeName(x) === 'list' || typeName(x) === 'map' ? x.toJS() : x, {
indent: 2,
})
.replace(/\n/g, '\n ')
.trim()

/**
* Looks up the type of a field in a GraphQL object type.
Expand Down Expand Up @@ -89,7 +92,7 @@ const validators = immutable.fromJS({
: immutable.fromJS([
{
path: ctx.get('path'),
message: `Expected list, found ${typeName(value)}:\n${toYAML(value)}`,
message: `Expected list, found ${typeName(value)}:\n ${toYAML(value)}`,
},
]),

Expand Down Expand Up @@ -120,7 +123,7 @@ const validators = immutable.fromJS({
: immutable.fromJS([
{
path: ctx.get('path'),
message: `Expected map, found ${typeName(value)}:\n${toYAML(value)}`,
message: `Expected map, found ${typeName(value)}:\n ${toYAML(value)}`,
},
])
},
Expand All @@ -131,7 +134,7 @@ const validators = immutable.fromJS({
: immutable.fromJS([
{
path: ctx.get('path'),
message: `Expected string, found ${typeName(value)}:\n${toYAML(value)}`,
message: `Expected string, found ${typeName(value)}:\n ${toYAML(value)}`,
},
]),

Expand All @@ -148,7 +151,7 @@ const validators = immutable.fromJS({
: immutable.fromJS([
{
path: ctx.get('path'),
message: `Expected filename, found ${typeName(value)}:\n${value}`,
message: `Expected filename, found ${typeName(value)}:\n ${value}`,
},
]),
})
Expand Down Expand Up @@ -183,7 +186,7 @@ const validateManifest = (value, type, schema) =>
: [
{
path: [],
message: `Expected non-empty value, found ${typeName(value)}:\n${value}`,
message: `Expected non-empty value, found ${typeName(value)}:\n ${value}`,
},
]

Expand Down

0 comments on commit 54d5452

Please sign in to comment.