Use errdefs package

This commit is contained in:
Brian Goff
2019-05-20 14:11:13 -07:00
parent b9711abff3
commit 02623170cc
24 changed files with 93 additions and 72 deletions

View File

@@ -6,8 +6,7 @@ import (
"os"
"contrib.go.opencensus.io/exporter/ocagent"
"github.com/cpuguy83/strongerrors"
"github.com/pkg/errors"
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
"go.opencensus.io/trace"
)
@@ -22,7 +21,7 @@ func NewOCAgentExporter(opts TracingExporterOptions) (trace.Exporter, error) {
if endpoint := os.Getenv("OCAGENT_ENDPOINT"); endpoint != "" {
agentOpts = append(agentOpts, ocagent.WithAddress(endpoint))
} else {
return nil, strongerrors.InvalidArgument(errors.New("must set endpoint address in OCAGENT_ENDPOINT"))
return nil, errdefs.InvalidInput("must set endpoint address in OCAGENT_ENDPOINT")
}
switch os.Getenv("OCAGENT_INSECURE") {
@@ -30,7 +29,7 @@ func NewOCAgentExporter(opts TracingExporterOptions) (trace.Exporter, error) {
case "1", "yes", "y", "on":
agentOpts = append(agentOpts, ocagent.WithInsecure())
default:
return nil, strongerrors.InvalidArgument(errors.New("invalid value for OCAGENT_INSECURE"))
return nil, errdefs.InvalidInput("invalid value for OCAGENT_INSECURE")
}
return ocagent.NewExporter(agentOpts...)

View File

@@ -1,8 +1,7 @@
package opencensus
import (
"github.com/cpuguy83/strongerrors"
"github.com/pkg/errors"
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
"go.opencensus.io/trace"
)
@@ -30,7 +29,7 @@ func RegisterTracingExporter(name string, f TracingExporterInitFunc) {
func GetTracingExporter(name string, opts TracingExporterOptions) (trace.Exporter, error) {
f, ok := tracingExporters[name]
if !ok {
return nil, strongerrors.NotFound(errors.Errorf("tracing exporter %q not found", name))
return nil, errdefs.NotFoundf("tracing exporter %q not found", name)
}
return f(opts)
}

View File

@@ -3,8 +3,7 @@ package opencensus
import (
"testing"
"github.com/cpuguy83/strongerrors"
"github.com/virtual-kubelet/virtual-kubelet/errdefs"
"go.opencensus.io/trace"
)
@@ -16,7 +15,7 @@ func TestGetTracingExporter(t *testing.T) {
}
_, err := GetTracingExporter("notexist", TracingExporterOptions{})
if !strongerrors.IsNotFound(err) {
if !errdefs.IsNotFound(err) {
t.Fatalf("expected not found error, got: %v", err)
}