Skip to content

Commit

Permalink
only allow specific error
Browse files Browse the repository at this point in the history
  • Loading branch information
lujiajing1126 committed Nov 15, 2023
1 parent 584a5b3 commit c517e86
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions tools/go-agent/instrument/plugins/instrument.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"bytes"
"embed"
"fmt"
"go/build"
"go/parser"
"go/token"
"io/fs"
Expand Down Expand Up @@ -51,6 +50,10 @@ import (
//go:embed templates
var templatesFS embed.FS

var (
errNoVersionFound = errors.New("no version found in the path of the source file")
)

type Instrument struct {
realInst instrument.Instrument
methodFilters []*instrument.Point
Expand Down Expand Up @@ -107,7 +110,7 @@ func (i *Instrument) CouldHandle(opts *api.CompileOptions) bool {
}
// check the version of the framework could handler
version, err := i.tryToFindThePluginVersion(opts, ins)
if err != nil {
if err != nil && !errors.Is(err, errNoVersionFound) {
logrus.Warnf("ignore the plugin %s, because %s", ins.Name(), err)
continue
}
Expand Down Expand Up @@ -551,11 +554,6 @@ func (i *Instrument) tryToFindThePluginVersion(opts *api.CompileOptions, ins ins
continue
}

// support local import. example: arg=../../../../toolkit/trace/api.go
if build.IsLocalImport(arg) {
continue
}

// example: github.com/Shopify/sarama
basePkg := ins.BasePackage()

Expand All @@ -568,7 +566,7 @@ func (i *Instrument) tryToFindThePluginVersion(opts *api.CompileOptions, ins ins
// arg example: github.com/!shopify/[email protected]/acl.go
_, afterPkg, found := strings.Cut(arg, escapedBasePkg)
if !found {
return "", fmt.Errorf("could not found the go version of the package %s, go file path: %s", basePkg, arg)
return "", errors.Wrapf(errNoVersionFound, "package %s, go file path: %s", basePkg, arg)
}

if !strings.HasPrefix(afterPkg, "@") {
Expand Down

0 comments on commit c517e86

Please sign in to comment.