Skip to content

Commit

Permalink
Error messaging for Schema
Browse files Browse the repository at this point in the history
Print better error messages when there is Parser Error , NotAValidType()
  • Loading branch information
Ranjani Renganathan committed May 23, 2017
1 parent a55c211 commit 138e087
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions jsonLoader.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,12 @@ func decodeJsonUsingNumber(r io.Reader) (interface{}, error) {
if err != nil {
return nil, err
}
_, isSlice := document.([]interface{})
_, isMap := document.(map[string]interface{})

if !isSlice && !isMap {
return nil, fmt.Errorf("Parse Error:Invalid JSON")
}

return document, nil

Expand Down
2 changes: 1 addition & 1 deletion locales.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ func (l DefaultLocale) ReferenceMustBeCanonical() string {
}

func (l DefaultLocale) NotAValidType() string {
return `{{.type}} is not a valid type -- `
return `has a primitive type that is NOT VALID -- given: {{.given}} Expected valid values are:{{.expected}}`
}

func (l DefaultLocale) Duplicated() string {
Expand Down
2 changes: 1 addition & 1 deletion schemaType.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (t *jsonSchemaType) IsTyped() bool {
func (t *jsonSchemaType) Add(etype string) error {

if !isStringInSlice(JSON_TYPES, etype) {
return errors.New(formatErrorDescription(Locale.NotAValidType(), ErrorDetails{"type": etype}))
return errors.New(formatErrorDescription(Locale.NotAValidType(), ErrorDetails{"given": "/" + etype + "/", "expected": JSON_TYPES}))
}

if t.Contains(etype) {
Expand Down

0 comments on commit 138e087

Please sign in to comment.