Skip to content

Commit

Permalink
Revert "feat: Optimize error message #13 (#25)"
Browse files Browse the repository at this point in the history
This reverts commit 3c40e15.
  • Loading branch information
vircoys authored Dec 23, 2022
1 parent 3c40e15 commit dc84f17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 68 deletions.
53 changes: 25 additions & 28 deletions pkg/errchain/error.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,15 @@ import (
"github.com/GuanceCloud/platypus/pkg/token"
)

type Position struct {
File string `json:"file"` // filename or filepath
Ln int `json:"ln"`
Col int `json:"col"`
Pos int `json:"pos"`
type FilePos struct {
FilePath string
Ln int
Col int
}

type PlError struct {
PosChain []Position `json:"pos_chain"`
Err string `json:"error"`
pos []FilePos
err string
}

type PlErrors []PlError
Expand All @@ -35,52 +34,50 @@ func (e PlErrors) Error() string {
}

func (e *PlError) Error() string {
if len(e.PosChain) == 0 {
if len(e.pos) == 0 {
return ""
}

var errr string

for i := 0; i < len(e.PosChain); i++ {
pos := e.PosChain[i]
for i := 0; i < len(e.pos); i++ {
pos := e.pos[i]
if i == 0 {
errr += fmt.Sprintf("%s:%d:%d: %s", pos.File, pos.Ln, pos.Col, e.Err)
errr += fmt.Sprintf("%s:%d:%d: %s", pos.FilePath, pos.Ln, pos.Col, e.err)
} else {
errr += fmt.Sprintf(
"\n%s:%d:%d:", e.PosChain[i].File,
e.PosChain[i].Ln, e.PosChain[i].Col)
"\n%s:%d:%d:", e.pos[i].FilePath,
e.pos[i].Ln, e.pos[i].Col)
}
}
return errr
}

func (e *PlError) ChainAppend(file string, pos token.LnColPos) *PlError {
e.PosChain = append(e.PosChain, Position{
File: file,
Ln: pos.Ln,
Col: pos.Col,
Pos: int(pos.Pos),
func (e *PlError) ChainAppend(filepath string, pos token.LnColPos) *PlError {
e.pos = append(e.pos, FilePos{
Ln: pos.Ln,
Col: pos.Col,
FilePath: filepath,
})
return e
}

func (e *PlError) Copy() *PlError {
return &PlError{
Err: e.Err,
PosChain: append([]Position{}, e.PosChain...),
err: e.err,
pos: append([]FilePos{}, e.pos...),
}
}

func NewErr(file string, pos token.LnColPos, err string) *PlError {
func NewErr(filepath string, pos token.LnColPos, err string) *PlError {
return &PlError{
PosChain: []Position{
pos: []FilePos{
{
File: file,
Ln: pos.Ln,
Col: pos.Col,
Pos: int(pos.Pos),
FilePath: filepath,
Col: pos.Col,
Ln: pos.Ln,
},
},
Err: err,
err: err,
}
}
39 changes: 0 additions & 39 deletions pkg/errchain/error_test.go

This file was deleted.

2 changes: 1 addition & 1 deletion pkg/token/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,13 @@ func (c *PosCache) LnCol(pos Pos) LnColPos {
}

return LnColPos{
Pos: pos,
Ln: int(ln) + 1,
Col: int(pos) - c.lineStartPos[ln] + 1,
}
}

func NewPosCache(query string) *PosCache {

cache := PosCache{
query: query,
lineStartPos: []int{0},
Expand Down

0 comments on commit dc84f17

Please sign in to comment.