diff --git a/go.mod b/go.mod index ab03afb..9a63ef6 100644 --- a/go.mod +++ b/go.mod @@ -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 ) diff --git a/go.sum b/go.sum index 523a8ff..c37a533 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/modfile/gop_test.go b/modfile/gop_test.go index 12dc526..61afc74 100644 --- a/modfile/gop_test.go +++ b/modfile/gop_test.go @@ -20,6 +20,7 @@ import ( "path/filepath" "testing" + "github.com/qiniu/x/errors" "golang.org/x/mod/modfile" ) @@ -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`, ` @@ -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) } }) } diff --git a/modfile/rule.go b/modfile/rule.go index f03ddbd..a0b591d 100644 --- a/modfile/rule.go +++ b/modfile/rule.go @@ -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, @@ -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, @@ -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() +} // -----------------------------------------------------------------------------