Skip to content

Commit

Permalink
fix: improve unknown map key error message
Browse files Browse the repository at this point in the history
  • Loading branch information
danielgtaylor committed Dec 10, 2021
1 parent 378f5a7 commit eace361
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MicroExpr

[![Go Reference](https://pkg.go.dev/badge/github.com/danielgtaylor/mexpr.svg)](https://pkg.go.dev/github.com/danielgtaylor/mexpr) [![Go Report Card](https://goreportcard.com/badge/github.com/danielgtaylor/mexpr)](https://goreportcard.com/report/github.com/danielgtaylor/mexpr)
[![Go Reference](https://pkg.go.dev/badge/github.com/danielgtaylor/mexpr.svg)](https://pkg.go.dev/github.com/danielgtaylor/mexpr) [![Go Report Card](https://goreportcard.com/badge/github.com/danielgtaylor/mexpr)](https://goreportcard.com/report/github.com/danielgtaylor/mexpr) ![GitHub tag (latest by date)](https://img.shields.io/github/v/tag/danielgtaylor/mexpr)

A small & fast dependency-free library for parsing micro expressions.

Expand Down
10 changes: 9 additions & 1 deletion typecheck.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package mexpr

import "strings"

type valueType string

const (
Expand Down Expand Up @@ -110,12 +112,18 @@ func (i *typeChecker) run(ast *Node, value interface{}) (*schema, Error) {
return v, nil
}
}
errValue := value
if m, ok := value.(map[string]interface{}); ok {
if v, ok := m[ast.Value.(string)]; ok {
return getSchema(v), nil
}
keys := []string{}
for k := range m {
keys = append(keys, k)
}
errValue = "map with keys [" + strings.Join(keys, ", ") + "]"
}
return nil, NewError(ast.Offset, ast.Length, "no property %v in %v", ast.Value, value)
return nil, NewError(ast.Offset, ast.Length, "no property %v in %v", ast.Value, errValue)
case NodeFieldSelect:
leftType, err := i.run(ast.Left, value)
if err != nil {
Expand Down

0 comments on commit eace361

Please sign in to comment.