From c517e86e5744859e6b4ee825ca3120a60c8a44f0 Mon Sep 17 00:00:00 2001 From: Megrez Lu Date: Wed, 15 Nov 2023 16:02:59 +0800 Subject: [PATCH] only allow specific error --- tools/go-agent/instrument/plugins/instrument.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tools/go-agent/instrument/plugins/instrument.go b/tools/go-agent/instrument/plugins/instrument.go index 5c7697de..bb82f658 100644 --- a/tools/go-agent/instrument/plugins/instrument.go +++ b/tools/go-agent/instrument/plugins/instrument.go @@ -21,7 +21,6 @@ import ( "bytes" "embed" "fmt" - "go/build" "go/parser" "go/token" "io/fs" @@ -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 @@ -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 } @@ -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() @@ -568,7 +566,7 @@ func (i *Instrument) tryToFindThePluginVersion(opts *api.CompileOptions, ins ins // arg example: github.com/!shopify/sarama@1.34.1/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, "@") {