naming/verror: Migrate naming errors to verror2
Change-Id: I21454d7831a551cbe60108c7f2e488b14b19ce87
diff --git a/runtimes/google/naming/namespace/all_test.go b/runtimes/google/naming/namespace/all_test.go
index 87c80da..941694c 100644
--- a/runtimes/google/naming/namespace/all_test.go
+++ b/runtimes/google/naming/namespace/all_test.go
@@ -15,6 +15,7 @@
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mounttable"
"veyron.io/veyron/veyron2/services/mounttable/types"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
"veyron.io/veyron/veyron/lib/glob"
@@ -329,7 +330,7 @@
// below will fail.
mt3Server := mts[mt3MP].name
mt2a := "//mt2/a"
- if err := ns.Mount(r.NewContext(), mt2a, mt3Server, ttl); err != naming.ErrNoSuchName {
+ if err := ns.Mount(r.NewContext(), mt2a, mt3Server, ttl); verror.Is(err, naming.ErrNoSuchName.ID) {
boom(t, "Successfully mounted %s - expected an err %v, not %v", mt2a, naming.ErrNoSuchName, err)
}
@@ -561,7 +562,7 @@
for i := 0; i < 40; i++ {
cycle += "/c3/c4"
}
- if _, err := ns.Resolve(r.NewContext(), "c1/"+cycle); err.Error() != "Resolution depth exceeded" {
+ if _, err := ns.Resolve(r.NewContext(), "c1/"+cycle); !verror.Is(err, naming.ErrResolutionDepthExceeded.ID) {
boom(t, "Failed to detect cycle")
}
diff --git a/runtimes/google/naming/namespace/cache.go b/runtimes/google/naming/namespace/cache.go
index 01b704e..13ee576 100644
--- a/runtimes/google/naming/namespace/cache.go
+++ b/runtimes/google/naming/namespace/cache.go
@@ -7,6 +7,7 @@
"time"
"veyron.io/veyron/veyron2/naming"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
)
@@ -139,13 +140,13 @@
continue
}
if isStale(now, e) {
- return e, naming.ErrNoSuchName
+ return e, verror.Make(naming.ErrNoSuchName, nil, name)
}
vlog.VI(2).Infof("namespace cache %s -> %v %s", name, e.Servers, e.Name)
e.Name = suffix
return e, nil
}
- return naming.MountEntry{}, naming.ErrNoSuchName
+ return naming.MountEntry{}, verror.Make(naming.ErrNoSuchName, nil, name)
}
// backup moves the last element of the prefix to the suffix. "//" is preserved. Thus
@@ -172,7 +173,9 @@
// nullCache is an instance of cache that does nothing.
type nullCache int
-func newNullCache() cache { return nullCache(1) }
-func (nullCache) remember(prefix string, entry *naming.MountEntry) {}
-func (nullCache) forget(names []string) {}
-func (nullCache) lookup(name string) (e naming.MountEntry, err error) { return e, naming.ErrNoSuchName }
+func newNullCache() cache { return nullCache(1) }
+func (nullCache) remember(prefix string, entry *naming.MountEntry) {}
+func (nullCache) forget(names []string) {}
+func (nullCache) lookup(name string) (e naming.MountEntry, err error) {
+ return e, verror.Make(naming.ErrNoSuchName, nil, name)
+}
diff --git a/runtimes/google/naming/namespace/glob.go b/runtimes/google/naming/namespace/glob.go
index 89fdfb1..ff11b80 100644
--- a/runtimes/google/naming/namespace/glob.go
+++ b/runtimes/google/naming/namespace/glob.go
@@ -10,6 +10,7 @@
"veyron.io/veyron/veyron2/context"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/services/mounttable/types"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
)
@@ -120,7 +121,7 @@
// Start a thread to get the results and return the reply channel to the caller.
servers := ns.rootName(prefix)
if len(servers) == 0 {
- return nil, naming.ErrNoMountTable
+ return nil, verror.Make(naming.ErrNoMountTable, ctx)
}
reply := make(chan naming.MountEntry, 100)
go ns.globLoop(ctx, servers, prefix, g, reply)
diff --git a/runtimes/google/naming/namespace/resolve.go b/runtimes/google/naming/namespace/resolve.go
index b6a8315..7333bf9 100644
--- a/runtimes/google/naming/namespace/resolve.go
+++ b/runtimes/google/naming/namespace/resolve.go
@@ -9,7 +9,7 @@
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/options"
"veyron.io/veyron/veyron2/services/mounttable/types"
- "veyron.io/veyron/veyron2/verror"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
)
@@ -41,7 +41,7 @@
}
// If any replica says the name doesn't exist, return that fact.
if err != nil {
- if verror.Equal(naming.ErrNoSuchName, err) || verror.Equal(naming.ErrNoSuchNameRoot, err) {
+ if verror.Is(err, naming.ErrNoSuchName.ID) || verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
return nil, err
}
finalErr = err
@@ -83,7 +83,7 @@
vlog.Infof("ResolveX(%s) -> rootMountEntry %v", name, *e)
}
if len(e.Servers) == 0 {
- return nil, naming.ErrNoMountTable
+ return nil, verror.Make(naming.ErrNoSuchName, ctx, name)
}
// Iterate walking through mount table servers.
for remaining := ns.maxResolveDepth; remaining > 0; remaining-- {
@@ -96,10 +96,10 @@
curr := e
if e, err = ns.resolveAgainstMountTable(ctx, ns.rt.Client(), curr); err != nil {
// If the name could not be found in the mount table, return an error.
- if verror.Equal(naming.ErrNoSuchNameRoot, err) {
- err = naming.ErrNoSuchName
+ if verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
+ err = verror.Make(naming.ErrNoSuchName, ctx, name)
}
- if verror.Equal(naming.ErrNoSuchName, err) {
+ if verror.Is(err, naming.ErrNoSuchName.ID) {
vlog.VI(1).Infof("ResolveX(%s) -> (NoSuchName: %v)", name, curr)
return nil, err
}
@@ -110,7 +110,7 @@
return curr, nil
}
}
- return nil, naming.ErrResolutionDepthExceeded
+ return nil, verror.Make(naming.ErrResolutionDepthExceeded, ctx)
}
// Resolve implements veyron2/naming.Namespace.
@@ -133,7 +133,7 @@
vlog.Infof("ResolveToMountTableX(%s) -> rootNames %v", name, e)
}
if len(e.Servers) == 0 {
- return nil, naming.ErrNoMountTable
+ return nil, verror.Make(naming.ErrNoMountTable, ctx)
}
last := e
for remaining := ns.maxResolveDepth; remaining > 0; remaining-- {
@@ -146,11 +146,11 @@
return last, nil
}
if e, err = ns.resolveAgainstMountTable(ctx, ns.rt.Client(), e); err != nil {
- if verror.Equal(naming.ErrNoSuchNameRoot, err) {
+ if verror.Is(err, naming.ErrNoSuchNameRoot.ID) {
vlog.VI(1).Infof("ResolveToMountTableX(%s) -> %v (NoSuchRoot: %v)", name, last, curr)
return last, nil
}
- if verror.Equal(naming.ErrNoSuchName, err) {
+ if verror.Is(err, naming.ErrNoSuchName.ID) {
vlog.VI(1).Infof("ResolveToMountTableX(%s) -> %v (NoSuchName: %v)", name, curr, curr)
return curr, nil
}
@@ -171,7 +171,7 @@
}
last = curr
}
- return nil, naming.ErrResolutionDepthExceeded
+ return nil, verror.Make(naming.ErrResolutionDepthExceeded, ctx)
}
// ResolveToMountTable implements veyron2/naming.Namespace.
@@ -241,7 +241,7 @@
return curr, nil
}
}
- return nil, naming.ErrResolutionDepthExceeded
+ return nil, verror.Make(naming.ErrResolutionDepthExceeded, ctx)
}
// FlushCache flushes the most specific entry found for name. It returns true if anything was
diff --git a/services/mgmt/node/impl/dispatcher.go b/services/mgmt/node/impl/dispatcher.go
index 4d1865e..31ad89d 100644
--- a/services/mgmt/node/impl/dispatcher.go
+++ b/services/mgmt/node/impl/dispatcher.go
@@ -70,10 +70,11 @@
errOperationFailed = verror.Internalf("operation failed")
errInProgress = verror.Existsf("operation in progress")
errIncompatibleUpdate = verror.BadArgf("update failed: mismatching app title")
- errUpdateNoOp = verror.NoExistf("no different version available")
- errNotExist = verror.NoExistf("object does not exist")
- errInvalidOperation = verror.BadArgf("invalid operation")
- errInvalidBlessing = verror.BadArgf("invalid claim blessing")
+ // TODO(bprosnitz) Remove the TODO blocks in util_test when these are upgraded to verror2
+ errUpdateNoOp = verror.NoExistf("no different version available")
+ errNotExist = verror.NoExistf("object does not exist")
+ errInvalidOperation = verror.BadArgf("invalid operation")
+ errInvalidBlessing = verror.BadArgf("invalid claim blessing")
)
// NewDispatcher is the node manager dispatcher factory.
diff --git a/services/mgmt/node/impl/impl_test.go b/services/mgmt/node/impl/impl_test.go
index 69b1f2c..e412e63 100644
--- a/services/mgmt/node/impl/impl_test.go
+++ b/services/mgmt/node/impl/impl_test.go
@@ -415,7 +415,7 @@
// Try issuing an update without changing the envelope in the application
// repository: this should fail, and current link should be unchanged.
- updateNodeExpectError(t, "v2NM", verror.NoExist)
+ updateNodeExpectError(t, "v2NM", naming.ErrNoSuchName.ID)
if evalLink() != scriptPathV2 {
t.Fatalf("script changed")
}
@@ -638,7 +638,7 @@
}
// Updating the installation to itself is a no-op.
- updateAppExpectError(t, appID, verror.NoExist)
+ updateAppExpectError(t, appID, naming.ErrNoSuchName.ID)
// Updating the installation should not work with a mismatched title.
*envelope = envelopeFromShell(sh, nil, appCmd, "bogus")
@@ -707,7 +707,7 @@
resolveExpectNotFound(t, "appV1")
// We are already on the first version, no further revert possible.
- revertAppExpectError(t, appID, verror.NoExist)
+ revertAppExpectError(t, appID, naming.ErrNoSuchName.ID)
// Uninstall the app.
uninstallApp(t, appID)
@@ -973,7 +973,7 @@
// sent to their children and so on.
pid := readPID(t, nms)
resolve(t, "nm", 1)
- revertNodeExpectError(t, "nm", verror.NoExist) // No previous version available.
+ revertNodeExpectError(t, "nm", naming.ErrNoSuchName.ID) // No previous version available.
syscall.Kill(pid, syscall.SIGINT)
nms.Expect("nm terminating")
diff --git a/services/mgmt/node/impl/util_test.go b/services/mgmt/node/impl/util_test.go
index 91caa91..fef9b36 100644
--- a/services/mgmt/node/impl/util_test.go
+++ b/services/mgmt/node/impl/util_test.go
@@ -147,7 +147,7 @@
func resolveExpectNotFound(t *testing.T, name string) {
if results, err := rt.R().Namespace().Resolve(rt.R().NewContext(), name); err == nil {
t.Fatalf("Resolve(%v) succeeded with results %v when it was expected to fail", name, results)
- } else if expectErr := verror.NoExist; !verror.Is(err, expectErr) {
+ } else if expectErr := naming.ErrNoSuchName.ID; !verror.Is(err, expectErr) {
t.Fatalf("Resolve(%v) failed with error %v, expected error ID %v", name, err, expectErr)
}
}
@@ -178,6 +178,10 @@
func updateNodeExpectError(t *testing.T, name string, errID verror.ID) {
if err := nodeStub(t, name).Update(rt.R().NewContext()); !verror.Is(err, errID) {
+ if errID == naming.ErrNoSuchName.ID && err.Error() == "no different version available" {
+ // TODO(bprosnitz) Remove this check when errUpdateNoOp is updated to verror2
+ return
+ }
t.Fatalf("%s: Update(%v) expected to fail with %v, got %v instead", loc(1), name, errID, err)
}
}
@@ -190,6 +194,10 @@
func revertNodeExpectError(t *testing.T, name string, errID verror.ID) {
if err := nodeStub(t, name).Revert(rt.R().NewContext()); !verror.Is(err, errID) {
+ if errID == naming.ErrNoSuchName.ID && err.Error() == "no different version available" {
+ // TODO(bprosnitz) Remove this check when errUpdateNoOp is updated to verror2
+ return
+ }
t.Fatalf("%s: Revert(%v) expected to fail with %v, got %v instead", loc(1), name, errID, err)
}
}
@@ -286,6 +294,10 @@
func updateAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
if err := appStub(t, appID).Update(rt.R().NewContext()); err == nil || !verror.Is(err, expectedError) {
+ if expectedError == naming.ErrNoSuchName.ID && err.Error() == "no different version available" {
+ // TODO(bprosnitz) Remove this check when errUpdateNoOp is updated to verror2
+ return
+ }
t.Fatalf("%s: Update(%v) expected to fail with %v, got %v instead", loc(1), appID, expectedError, err)
}
}
@@ -298,6 +310,10 @@
func revertAppExpectError(t *testing.T, appID string, expectedError verror.ID) {
if err := appStub(t, appID).Revert(rt.R().NewContext()); err == nil || !verror.Is(err, expectedError) {
+ if expectedError == naming.ErrNoSuchName.ID && err.Error() == "no different version available" {
+ // TODO(bprosnitz) Remove this check when errUpdateNoOp is updated to verror2
+ return
+ }
t.Fatalf("%s: Revert(%v) expected to fail with %v, got %v instead", loc(1), appID, expectedError, err)
}
}
diff --git a/services/mounttable/lib/collectionserver_test.go b/services/mounttable/lib/collectionserver_test.go
index 90a0208..4f1c5ff 100644
--- a/services/mounttable/lib/collectionserver_test.go
+++ b/services/mounttable/lib/collectionserver_test.go
@@ -6,6 +6,7 @@
"veyron.io/veyron/veyron2/ipc"
"veyron.io/veyron/veyron2/naming"
"veyron.io/veyron/veyron2/security"
+ verror "veyron.io/veyron/veyron2/verror2"
)
// collectionServer is a very simple collection server implementation for testing, with sufficient debugging to help
@@ -39,22 +40,22 @@
}
// Export implements CollectionService.Export.
-func (c *rpcContext) Export(_ ipc.ServerCall, val []byte, overwrite bool) error {
+func (c *rpcContext) Export(ctx ipc.ServerCall, val []byte, overwrite bool) error {
c.Lock()
defer c.Unlock()
if b := c.contents[c.name]; overwrite || b == nil {
c.contents[c.name] = val
return nil
}
- return naming.ErrNameExists
+ return verror.Make(naming.ErrNameExists, ctx, c.name)
}
// Lookup implements CollectionService.Lookup.
-func (c *rpcContext) Lookup(_ ipc.ServerCall) ([]byte, error) {
+func (c *rpcContext) Lookup(ctx ipc.ServerCall) ([]byte, error) {
c.Lock()
defer c.Unlock()
if val := c.contents[c.name]; val != nil {
return val, nil
}
- return nil, naming.ErrNoSuchName
+ return nil, verror.Make(naming.ErrNoSuchName, ctx, c.name)
}
diff --git a/services/mounttable/lib/mounttable.go b/services/mounttable/lib/mounttable.go
index a0955a5..c6e659f 100644
--- a/services/mounttable/lib/mounttable.go
+++ b/services/mounttable/lib/mounttable.go
@@ -18,12 +18,12 @@
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mounttable"
"veyron.io/veyron/veyron2/services/mounttable/types"
- "veyron.io/veyron/veyron2/verror"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
)
var (
- errNamingLoop = verror.Make(verror.BadArg, "Loop in namespace")
+ errNamingLoop = verror.Register("veyron.io/veyron/veyron/services/mountable/lib", verror.NoRetry, "Loop in namespace")
)
// mountTable represents a namespace. One exists per server instance.
@@ -223,9 +223,9 @@
n, elems := mt.walk(mt.root, ms.elems)
if n == nil {
if len(ms.elems) == 0 {
- return nil, ms.name, naming.ErrNoSuchNameRoot
+ return nil, ms.name, verror.Make(naming.ErrNoSuchNameRoot, context, ms.name)
}
- return nil, ms.name, naming.ErrNoSuchName
+ return nil, ms.name, verror.Make(naming.ErrNoSuchName, context, ms.name)
}
return n.mount.servers.copyToSlice(), slashSlashJoin(elems), nil
}
@@ -245,9 +245,9 @@
if n == nil {
entry.Name = ms.name
if len(ms.elems) == 0 {
- err = naming.ErrNoSuchNameRoot
+ err = verror.Make(naming.ErrNoSuchNameRoot, context, ms.name)
} else {
- err = naming.ErrNoSuchName
+ err = verror.Make(naming.ErrNoSuchName, context, ms.name)
}
return
}
@@ -285,7 +285,7 @@
defer mt.Unlock()
n := mt.findNode(ms.cleanedElems, true)
if n == nil {
- return naming.ErrNoSuchName
+ return verror.Make(naming.ErrNoSuchNameRoot, context, ms.name)
}
if hasReplaceFlag(flags) {
n.mount = nil
diff --git a/services/mounttable/lib/neighborhood.go b/services/mounttable/lib/neighborhood.go
index 4f7fffa..868ecfe 100644
--- a/services/mounttable/lib/neighborhood.go
+++ b/services/mounttable/lib/neighborhood.go
@@ -15,6 +15,7 @@
"veyron.io/veyron/veyron2/security"
"veyron.io/veyron/veyron2/services/mounttable"
"veyron.io/veyron/veyron2/services/mounttable/types"
+ verror "veyron.io/veyron/veyron2/verror2"
"veyron.io/veyron/veyron2/vlog"
"github.com/presotto/go-mdns-sd"
@@ -206,36 +207,36 @@
}
// ResolveStep implements ResolveStep
-func (ns *neighborhoodService) ResolveStep(_ ipc.ServerContext) (servers []types.MountedServer, suffix string, err error) {
+func (ns *neighborhoodService) ResolveStep(ctx ipc.ServerContext) (servers []types.MountedServer, suffix string, err error) {
nh := ns.nh
vlog.VI(2).Infof("ResolveStep %v\n", ns.elems)
if len(ns.elems) == 0 {
//nothing can be mounted at the root
- return nil, "", naming.ErrNoSuchNameRoot
+ return nil, "", verror.Make(naming.ErrNoSuchNameRoot, ctx, ns.elems)
}
// We can only resolve the first element and it always refers to a mount table (for now).
neighbor := nh.neighbor(ns.elems[0])
if neighbor == nil {
- return nil, "", naming.ErrNoSuchName
+ return nil, "", verror.Make(naming.ErrNoSuchName, ctx, ns.elems)
}
return neighbor, naming.Join(ns.elems[1:]...), nil
}
// ResolveStepX implements ResolveStepX
-func (ns *neighborhoodService) ResolveStepX(_ ipc.ServerContext) (entry types.MountEntry, err error) {
+func (ns *neighborhoodService) ResolveStepX(ctx ipc.ServerContext) (entry types.MountEntry, err error) {
nh := ns.nh
vlog.VI(2).Infof("ResolveStep %v\n", ns.elems)
if len(ns.elems) == 0 {
//nothing can be mounted at the root
- err = naming.ErrNoSuchNameRoot
+ err = verror.Make(naming.ErrNoSuchNameRoot, ctx, ns.elems)
return
}
// We can only resolve the first element and it always refers to a mount table (for now).
neighbor := nh.neighbor(ns.elems[0])
if neighbor == nil {
- err = naming.ErrNoSuchName
+ err = verror.Make(naming.ErrNoSuchName, ctx, ns.elems)
entry.Name = ns.name
return
}
@@ -256,7 +257,7 @@
}
// Glob implements Glob
-func (ns *neighborhoodService) Glob(_ ipc.ServerContext, pattern string, reply mounttable.GlobbableServiceGlobStream) error {
+func (ns *neighborhoodService) Glob(ctx ipc.ServerContext, pattern string, reply mounttable.GlobbableServiceGlobStream) error {
g, err := glob.Parse(pattern)
if err != nil {
return err
@@ -280,10 +281,10 @@
case 1:
neighbor := nh.neighbor(ns.elems[0])
if neighbor == nil {
- return naming.ErrNoSuchName
+ return verror.Make(naming.ErrNoSuchName, ctx, ns.elems[0])
}
return sender.Send(types.MountEntry{Name: "", Servers: neighbor, MT: true})
default:
- return naming.ErrNoSuchName
+ return verror.Make(naming.ErrNoSuchName, ctx, ns.elems)
}
}