Skip to content

Commit

Permalink
use errors.List
Browse files Browse the repository at this point in the history
  • Loading branch information
xushiwei committed Jun 17, 2022
1 parent fd63569 commit 4dd28ed
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ module github.com/goplus/mod
go 1.16

require (
github.com/qiniu/x v1.11.8
github.com/qiniu/x v1.11.9
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
)
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
github.com/qiniu/x v1.11.8 h1:Jol2Nm/wNIUSk+oxebNZbYPZ1gW/UI4C6FsN5xZzcQQ=
github.com/qiniu/x v1.11.8/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
github.com/qiniu/x v1.11.9 h1:IfQNdeNcK43Q1+b/LdrcqmWjlhxq051YVBnua8J2qN8=
github.com/qiniu/x v1.11.9/go.mod h1:03Ni9tj+N2h2aKnAz+6N0Xfl8FwMEDRC2PAlxekASDs=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
Expand Down
9 changes: 5 additions & 4 deletions modfile/gop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"path/filepath"
"testing"

"github.com/qiniu/x/errors"
"golang.org/x/mod/modfile"
)

Expand Down Expand Up @@ -224,7 +225,7 @@ register -
classfile .gmx .spx github.com/goplus/spx math
classfile .gmx .spx github.com/goplus/spx math
`)
doTestParseErr(t, `gop.mod:2: usage: classfile projExt workExt [classFilePkgPath ...]`, `
doTestParseErr(t, `gop.mod:2: usage: classfile projExt workExt classFilePkgPath ...`, `
classfile .gmx .spx
`)
doTestParseErr(t, `gop.mod:2: ext . invalid: invalid ext format`, `
Expand All @@ -247,12 +248,12 @@ go 1.x
func doTestParseErr(t *testing.T, errMsg string, gopmod string) {
t.Run(errMsg, func(t *testing.T) {
_, err := Parse("gop.mod", []byte(gopmod), nil)
if err == nil {
if err == nil || err.Error() == "" {
t.Fatal("Parse: no error?")
return
}
if err.Error() != errMsg {
t.Error("Parse got:", err, "\nExpected:", errMsg)
if errRet := errors.Summary(err); errRet != errMsg {
t.Error("Parse got:", errRet, "\nExpected:", errMsg)
}
})
}
Expand Down
22 changes: 18 additions & 4 deletions modfile/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func parseToFile(file string, data []byte, fix VersionFixer, strict bool) (parse

func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string, strict bool) {
wrapModPathError := func(modPath string, err error) {
*errs = append(*errs, Error{
errs.Add(&Error{
Filename: f.Syntax.Name,
Pos: line.Start,
ModPath: modPath,
Expand All @@ -141,7 +141,7 @@ func (f *File) parseVerb(errs *ErrorList, verb string, line *Line, args []string
})
}
wrapError1 := func(err error) {
*errs = append(*errs, Error{
errs.Add(&Error{
Filename: f.Syntax.Name,
Pos: line.Start,
Err: err,
Expand Down Expand Up @@ -403,8 +403,22 @@ func (e *InvalidExtError) Error() string {

func (e *InvalidExtError) Unwrap() error { return e.Err }

type ErrorList = modfile.ErrorList
type Error = modfile.Error
type ErrorList = errors.List
type Error modfile.Error

func (p *Error) Error() string {
return (*modfile.Error)(p).Error()
}

func (p *Error) Unwrap() error {
return p.Err
}

func (p *Error) Summary() string {
cpy := *(*modfile.Error)(p)
cpy.Err = errors.New(errors.Summary(p.Unwrap()))
return cpy.Error()
}

// -----------------------------------------------------------------------------

Expand Down

0 comments on commit 4dd28ed

Please sign in to comment.