x/ref: Remove verror.Is and verror.Equal
It's simpler to just use verror.ErrorID instead
MultiPart: 2/2
Change-Id: I12886abe7e7d6345186022b9127d45c6fff54ec6
diff --git a/profiles/internal/naming/namespace/all_test.go b/profiles/internal/naming/namespace/all_test.go
index d4d37f7..7ff78dc 100644
--- a/profiles/internal/naming/namespace/all_test.go
+++ b/profiles/internal/naming/namespace/all_test.go
@@ -327,7 +327,7 @@
// /mt2 is not an endpoint. Thus, the example below will fail.
mt3Server := mts[mt3MP].name
mt2a := "/mt2/a"
- if err := ns.Mount(c, mt2a, mt3Server, ttl); verror.Is(err, naming.ErrNoSuchName.ID) {
+ if err := ns.Mount(c, mt2a, mt3Server, ttl); verror.ErrorID(err) == naming.ErrNoSuchName.ID {
boom(t, "Successfully mounted %s - expected an err %v, not %v", mt2a, naming.ErrNoSuchName, err)
}
@@ -570,7 +570,7 @@
for i := 0; i < 40; i++ {
cycle += "/c3/c4"
}
- if _, err := ns.Resolve(c, "c1/"+cycle); !verror.Is(err, naming.ErrResolutionDepthExceeded.ID) {
+ if _, err := ns.Resolve(c, "c1/"+cycle); verror.ErrorID(err) != naming.ErrResolutionDepthExceeded.ID {
boom(t, "Failed to detect cycle")
}
@@ -664,7 +664,7 @@
for _, root := range []string{hproot, eproot} {
name := naming.JoinAddressName(root, "mt")
// Rooted name resolutions should fail authorization because of the "otherrot"
- if e, err := resolve(name); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ if e, err := resolve(name); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Errorf("resolve(%q) returned (%v, errorid=%v %v), wanted errorid=%v", name, e, verror.ErrorID(err), err, verror.ErrNotTrusted.ID)
}
// But not fail if the skip-authorization option is provided
@@ -673,7 +673,7 @@
}
// The namespace root from the context should be authorized as well.
ctx, ns, _ := v23.SetNewNamespace(clientCtx, naming.JoinAddressName(root, ""))
- if e, err := ns.Resolve(ctx, "mt/server"); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ if e, err := ns.Resolve(ctx, "mt/server"); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Errorf("resolve with root=%q returned (%v, errorid=%v %v), wanted errorid=%v", root, e, verror.ErrorID(err), err, verror.ErrNotTrusted.ID)
}
if _, err := ns.Resolve(ctx, "mt/server", options.SkipServerEndpointAuthorization{}); err != nil {
@@ -693,7 +693,7 @@
if e, err := resolve("mt/server", options.SkipServerEndpointAuthorization{}); err != nil {
t.Errorf("Resolve should succeed when skipping server authorization. Got (%v, %v)", e, err)
- } else if e, err := resolve("mt/server"); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ } else if e, err := resolve("mt/server"); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Errorf("Resolve should have failed with %q because an attacker has taken over the intermediate mounttable. Got (%+v, errorid=%q:%v)", verror.ErrNotTrusted.ID, e, verror.ErrorID(err), err)
}
}
diff --git a/profiles/internal/naming/namespace/resolve.go b/profiles/internal/naming/namespace/resolve.go
index 59f5f2a..07e22d2 100644
--- a/profiles/internal/naming/namespace/resolve.go
+++ b/profiles/internal/naming/namespace/resolve.go
@@ -40,7 +40,7 @@
entry := new(naming.MountEntry)
if err := call.Finish(entry); err != nil {
// If any replica says the name doesn't exist, return that fact.
- if verror.Is(err, naming.ErrNoSuchName.ID) || verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
+ if verror.ErrorID(err) == naming.ErrNoSuchName.ID || verror.ErrorID(err) == naming.ErrNoSuchNameRoot.ID {
return nil, err
}
// Keep track of the final error and continue with next server.
@@ -97,7 +97,7 @@
vlog.VI(1).Infof("Resolve(%s) -> %v", name, curr)
return curr, nil
}
- if verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
+ if verror.ErrorID(err) == naming.ErrNoSuchNameRoot.ID {
err = verror.New(naming.ErrNoSuchName, ctx, name)
}
vlog.VI(1).Infof("Resolve(%s) -> (%s: %v)", err, name, curr)
@@ -132,11 +132,11 @@
return last, nil
}
if e, err = ns.resolveAgainstMountTable(ctx, client, e, callOpts...); err != nil {
- if verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
+ if verror.ErrorID(err) == naming.ErrNoSuchNameRoot.ID {
vlog.VI(1).Infof("ResolveToMountTable(%s) -> %v (NoSuchRoot: %v)", name, last, curr)
return last, nil
}
- if verror.Is(err, naming.ErrNoSuchName.ID) {
+ if verror.ErrorID(err) == naming.ErrNoSuchName.ID {
vlog.VI(1).Infof("ResolveToMountTable(%s) -> %v (NoSuchName: %v)", name, curr, curr)
return curr, nil
}
diff --git a/profiles/internal/rpc/client.go b/profiles/internal/rpc/client.go
index 194d12a..3aab4f9 100644
--- a/profiles/internal/rpc/client.go
+++ b/profiles/internal/rpc/client.go
@@ -389,7 +389,7 @@
// We always return NoServers as the error so that the caller knows
// that's ok to retry the operation since the name may be registered
// in the near future.
- if verror.Is(err, naming.ErrNoSuchName.ID) {
+ if verror.ErrorID(err) == naming.ErrNoSuchName.ID {
return nil, verror.RetryRefetch, verror.New(verror.ErrNoServers, ctx, name)
}
return nil, verror.NoRetry, verror.New(verror.ErrNoServers, ctx, name, err)
@@ -467,7 +467,7 @@
case <-timeoutChan:
vlog.VI(2).Infof("rpc: timeout on connection to server %v ", name)
_, _, err := c.failedTryCall(ctx, name, method, responses, ch)
- if !verror.Is(err, verror.ErrTimeout.ID) {
+ if verror.ErrorID(err) != verror.ErrTimeout.ID {
return nil, verror.NoRetry, verror.New(verror.ErrTimeout, ctx, err)
}
return nil, verror.NoRetry, err
@@ -578,7 +578,7 @@
for _, r := range responses {
if r != nil && r.err != nil {
switch {
- case verror.Is(r.err, verror.ErrNotTrusted.ID) || verror.Is(r.err, errAuthError.ID):
+ case verror.ErrorID(r.err) == verror.ErrNotTrusted.ID || verror.ErrorID(r.err) == errAuthError.ID:
untrusted = append(untrusted, "("+r.err.Error()+") ")
default:
noconn = append(noconn, "("+r.err.Error()+") ")
@@ -715,7 +715,7 @@
return verror.New(verror.ErrInternal, fc.ctx, err)
}
switch {
- case verror.Is(err, verror.ErrBadProtocol.ID):
+ case verror.ErrorID(err) == verror.ErrBadProtocol.ID:
switch fc.ctx.Err() {
case context.DeadlineExceeded:
// TODO(cnicolaou,m3b): reintroduce 'append' when the new verror API is done.
@@ -726,7 +726,7 @@
//return verror.Append(verror.New(verror.ErrCanceled, fc.ctx), verr)
return verror.New(verror.ErrCanceled, fc.ctx, err.Error())
}
- case verror.Is(err, verror.ErrTimeout.ID):
+ case verror.ErrorID(err) == verror.ErrTimeout.ID:
// Canceled trumps timeout.
if fc.ctx.Err() == context.Canceled {
// TODO(cnicolaou,m3b): reintroduce 'append' when the new verror API is done.
@@ -917,7 +917,7 @@
if fc.response.Error != nil {
// TODO(cnicolaou): remove verror.ErrNoAccess with verror version
// when rpc.Server is converted.
- if verror.Is(fc.response.Error, verror.ErrNoAccess.ID) && fc.dc != nil {
+ if verror.ErrorID(fc.response.Error) == verror.ErrNoAccess.ID && fc.dc != nil {
// In case the error was caused by a bad discharge, we do not want to get stuck
// with retrying again and again with this discharge. As there is no direct way
// to detect it, we conservatively flush all discharges we used from the cache.
diff --git a/profiles/internal/rpc/full_test.go b/profiles/internal/rpc/full_test.go
index 05314cb..5d555d3 100644
--- a/profiles/internal/rpc/full_test.go
+++ b/profiles/internal/rpc/full_test.go
@@ -307,7 +307,7 @@
// Check that we can no longer serve after Stop.
err := server.AddName("name doesn't matter")
- if err == nil || !verror.Is(err, verror.ErrBadState.ID) {
+ if err == nil || verror.ErrorID(err) != verror.ErrBadState.ID {
t.Errorf("either no error, or a wrong error was returned: %v", err)
}
vlog.VI(1).Info("server.Stop DONE")
@@ -375,7 +375,7 @@
if err == nil && id.ID == "" {
return true
}
- return verror.Is(err, id.ID)
+ return verror.ErrorID(err) == id.ID
}
func runServer(t *testing.T, ctx *context.T, ns ns.Namespace, principal security.Principal, name string, obj interface{}, opts ...rpc.ServerOpt) stream.Manager {
@@ -642,7 +642,7 @@
}
defer client.Close()
ctx, _ = v23.SetPrincipal(ctx, pclient)
- if _, err := client.StartCall(ctx, "mountpoint/server", "Closure", nil); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ if _, err := client.StartCall(ctx, "mountpoint/server", "Closure", nil); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Errorf("Got error %v (errorid=%v), want errorid=%v", err, verror.ErrorID(err), verror.ErrNotTrusted.ID)
}
// But the RPC should succeed if the client explicitly
@@ -769,7 +769,7 @@
err = call.Finish(results...)
if got, want := err, test.finishErr; (got == nil) != (want == nil) {
t.Errorf(`%s call.Finish got error "%v", want "%v'`, name(test), got, want)
- } else if want != nil && !verror.Is(got, verror.ErrorID(want)) {
+ } else if want != nil && verror.ErrorID(got) != verror.ErrorID(want) {
t.Errorf(`%s call.Finish got error "%v", want "%v"`, name(test), got, want)
}
checkResultPtrs(t, name(test), results, test.results)
@@ -1137,7 +1137,7 @@
t.Errorf(`%s call.Finish got error: "%v", wanted the RPC to succeed`, name, err)
} else if err == nil && !test.authorized {
t.Errorf("%s call.Finish succeeded, expected authorization failure", name)
- } else if !test.authorized && !verror.Is(err, verror.ErrNoAccess.ID) {
+ } else if !test.authorized && verror.ErrorID(err) != verror.ErrNoAccess.ID {
t.Errorf("%s. call.Finish returned error %v(%v), wanted %v", name, verror.ErrorID(verror.Convert(verror.ErrNoAccess, nil, err)), err, verror.ErrNoAccess)
}
}
@@ -1506,7 +1506,7 @@
ctx, _ = v23.SetPrincipal(ctx, pclient)
_, err := b.client.StartCall(ctx, "incompatible/suffix", "Echo", []interface{}{"foo"}, options.NoRetry{})
- if !verror.Is(err, verror.ErrNoServers.ID) {
+ if verror.ErrorID(err) != verror.ErrNoServers.ID {
t.Errorf("Expected error %s, found: %v", verror.ErrNoServers, err)
}
@@ -1654,7 +1654,7 @@
if call != nil {
t.Errorf("Expected nil interface got: %#v", call)
}
- if !verror.Is(err, verror.ErrBadArg.ID) {
+ if verror.ErrorID(err) != verror.ErrBadArg.ID {
t.Errorf("Expected an BadArg error, got: %s", err.Error())
}
}
@@ -1956,7 +1956,7 @@
t.Errorf("Expected call to succeed but got %v", err)
}
// ...but fail if they differ.
- if _, err = client.StartCall(ctx, mountName, "Closure", nil, options.SkipServerEndpointAuthorization{}, options.ServerPublicKey{pother.PublicKey()}); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ if _, err = client.StartCall(ctx, mountName, "Closure", nil, options.SkipServerEndpointAuthorization{}, options.ServerPublicKey{pother.PublicKey()}); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Errorf("got %v, want %v", verror.ErrorID(err), verror.ErrNotTrusted.ID)
}
}
diff --git a/profiles/internal/rpc/server_test.go b/profiles/internal/rpc/server_test.go
index 403ce73..ce935c9 100644
--- a/profiles/internal/rpc/server_test.go
+++ b/profiles/internal/rpc/server_test.go
@@ -102,11 +102,11 @@
}
defer server.Stop()
_, err = server.Listen(rpc.ListenSpec{})
- if !verror.Is(err, verror.ErrBadArg.ID) {
+ if verror.ErrorID(err) != verror.ErrBadArg.ID {
t.Fatalf("expected a BadArg error: got %v", err)
}
_, err = server.Listen(rpc.ListenSpec{Addrs: rpc.ListenAddrs{{"tcp", "*:0"}}})
- if !verror.Is(err, verror.ErrBadArg.ID) {
+ if verror.ErrorID(err) != verror.ErrBadArg.ID {
t.Fatalf("expected a BadArg error: got %v", err)
}
_, err = server.Listen(rpc.ListenSpec{
@@ -114,7 +114,7 @@
{"tcp", "*:0"},
{"tcp", "127.0.0.1:0"},
}})
- if verror.Is(err, verror.ErrBadArg.ID) {
+ if verror.ErrorID(err) == verror.ErrBadArg.ID {
t.Fatalf("expected a BadArg error: got %v", err)
}
status := server.Status()
@@ -122,7 +122,7 @@
t.Fatalf("got %s, want %s", got, want)
}
_, err = server.Listen(rpc.ListenSpec{Addrs: rpc.ListenAddrs{{"tcp", "*:0"}}})
- if !verror.Is(err, verror.ErrBadArg.ID) {
+ if verror.ErrorID(err) != verror.ErrBadArg.ID {
t.Fatalf("expected a BadArg error: got %v", err)
}
status = server.Status()
@@ -237,7 +237,7 @@
defer shutdown()
expectBadState := func(err error) {
- if !verror.Is(err, verror.ErrBadState.ID) {
+ if verror.ErrorID(err) != verror.ErrBadState.ID {
t.Fatalf("%s: unexpected error: %v", loc(1), err)
}
}
diff --git a/profiles/internal/rpc/test/client_test.go b/profiles/internal/rpc/test/client_test.go
index 4c831f4..fafec63 100644
--- a/profiles/internal/rpc/test/client_test.go
+++ b/profiles/internal/rpc/test/client_test.go
@@ -254,7 +254,7 @@
name := naming.JoinAddressName(naming.FormatEndpoint("tcp", "203.0.113.10:443"), "")
client := v23.GetClient(ctx)
_, err := client.StartCall(ctx, name, "echo", []interface{}{"args don't matter"})
- if !verror.Is(err, verror.ErrTimeout.ID) {
+ if verror.ErrorID(err) != verror.ErrTimeout.ID {
t.Fatalf("wrong error: %s", err)
}
}
@@ -296,7 +296,7 @@
func testForVerror(t *testing.T, err error, verr verror.IDAction) {
_, file, line, _ := runtime.Caller(1)
loc := fmt.Sprintf("%s:%d", filepath.Base(file), line)
- if !verror.Is(err, verr.ID) {
+ if verror.ErrorID(err) != verr.ID {
if _, ok := err.(verror.E); !ok {
t.Fatalf("%s: err %v not a verror", loc, err)
}
@@ -469,7 +469,7 @@
ctx, _ = context.WithTimeout(ctx, 300*time.Millisecond)
call, err := v23.GetClient(ctx).StartCall(ctx, name, "Source", []interface{}{want})
if err != nil {
- if !verror.Is(err, verror.ErrTimeout.ID) {
+ if verror.ErrorID(err) != verror.ErrTimeout.ID {
t.Fatalf("verror should be a timeout not %s: stack %s",
err, verror.Stack(err))
}
diff --git a/profiles/internal/rpc/test/proxy_test.go b/profiles/internal/rpc/test/proxy_test.go
index 3a8c154..fb89398 100644
--- a/profiles/internal/rpc/test/proxy_test.go
+++ b/profiles/internal/rpc/test/proxy_test.go
@@ -350,7 +350,7 @@
verifyMountMissing(t, ctx, ns, name)
status = server.Status()
- if len(status.Proxies) != 1 || status.Proxies[0].Proxy != spec.Proxy || !verror.Is(status.Proxies[0].Error, verror.ErrNoServers.ID) {
+ if len(status.Proxies) != 1 || status.Proxies[0].Proxy != spec.Proxy || verror.ErrorID(status.Proxies[0].Error) != verror.ErrNoServers.ID {
t.Fatalf("proxy status is incorrect: %v", status.Proxies)
}
diff --git a/profiles/internal/rpc/testutil_test.go b/profiles/internal/rpc/testutil_test.go
index bb43fdd..b48f6c6 100644
--- a/profiles/internal/rpc/testutil_test.go
+++ b/profiles/internal/rpc/testutil_test.go
@@ -48,7 +48,7 @@
if !ok {
t.Errorf("%s result %d got type %T, want %T", name, ix, g, w)
}
- if !verror.Is(g, w.ID) {
+ if verror.ErrorID(g) != w.ID {
t.Errorf("%s result %d got %v, want %v", name, ix, g, w)
}
default:
diff --git a/profiles/internal/rt/ipc_test.go b/profiles/internal/rt/ipc_test.go
index e7e05e3..d100b76 100644
--- a/profiles/internal/rt/ipc_test.go
+++ b/profiles/internal/rt/ipc_test.go
@@ -342,7 +342,7 @@
return nil
}
- if err := makeCall(); !verror.Is(err, verror.ErrNotTrusted.ID) {
+ if err := makeCall(); verror.ErrorID(err) != verror.ErrNotTrusted.ID {
t.Fatalf("got error %v, expected %v", err, verror.ErrNotTrusted.ID)
}
ds.mu.Lock()
@@ -368,7 +368,7 @@
if err := pserver.BlessingStore().SetDefault(rootServerInvalidTPCaveat); err != nil {
t.Fatal(err)
}
- if call, err := client.StartCall(clientCtx, serverName, "EchoBlessings", nil); verror.Is(err, verror.ErrNoAccess.ID) {
+ if call, err := client.StartCall(clientCtx, serverName, "EchoBlessings", nil); verror.ErrorID(err) == verror.ErrNoAccess.ID {
remoteBlessings, _ := call.RemoteBlessings()
t.Errorf("client.StartCall passed unexpectedly with remote end authenticated as: %v", remoteBlessings)
}