Skip to content

Commit

Permalink
feat: return path position when out-of-range error
Browse files Browse the repository at this point in the history
  • Loading branch information
AsterDY committed Feb 17, 2024
1 parent 7648382 commit c15a8e7
Show file tree
Hide file tree
Showing 3 changed files with 1,124 additions and 1,110 deletions.
12 changes: 12 additions & 0 deletions ast/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ var (
ErrInvalidPath error = newError(_ERR_UNSUPPORT_TYPE, "path must be either int(>=0) or string")
)

// ErrIndexOutOfRange indicates a integer path is out of range
type ErrIndexOutOfRange struct {
New bool // tells ff the error happens at a existed array or newly-created array (SetByPath() allow create new nodes)
Pos int // the position (not value) of the path in path array
}

// Error
func (e ErrIndexOutOfRange) Error() string {
return fmt.Sprintf("%dth path is out of range", e.Pos)
}

// Parser
type Parser struct {
p int
s string
Expand Down
Loading

0 comments on commit c15a8e7

Please sign in to comment.