veyron.io/veyron/veyron/security/agent: Convert to use verror2
This change updates veyron.io/veyron/veyron/security/agent/{keymgr,server}
to use verror2.
The import statement renames verror2 to make the upcoming removal of verror
and subsequent renaming of verror2 to verror easier.
Change-Id: I6b06c55fcc65e693dd6cfcace369de16f633ac24
diff --git a/security/agent/keymgr/client.go b/security/agent/keymgr/client.go
index 7a93f31..fa36a4c 100644
--- a/security/agent/keymgr/client.go
+++ b/security/agent/keymgr/client.go
@@ -11,7 +11,17 @@
"veyron.io/veyron/veyron/lib/unixfd"
"veyron.io/veyron/veyron/security/agent/server"
"veyron.io/veyron/veyron2/context"
- "veyron.io/veyron/veyron2/verror"
+ verror "veyron.io/veyron/veyron2/verror2"
+)
+
+const pkgPath = "veyron.io/veyron/veyron/security/agent/keymgr"
+
+// Errors
+var (
+ errInvalidResponse = verror.Register(pkgPath+".errInvalidResponse",
+ verror.NoRetry, "{1:}{2:} invalid response from agent. (expected {3} bytes, got {4})")
+ errInvalidKeyHandle = verror.Register(pkgPath+".errInvalidKeyHandle",
+ verror.NoRetry, "{1:}{2:} Invalid key handle")
)
const defaultManagerSocket = 4
@@ -42,7 +52,7 @@
// NewPrincipal creates a new principal and returns the handle and a socket serving
// the principal.
// Typically the socket will be passed to a child process using cmd.ExtraFiles.
-func (a *Agent) NewPrincipal(_ context.T, inMemory bool) (handle []byte, conn *os.File, err error) {
+func (a *Agent) NewPrincipal(ctx context.T, inMemory bool) (handle []byte, conn *os.File, err error) {
req := make([]byte, 1)
if inMemory {
req[0] = 1
@@ -61,7 +71,7 @@
}
if n != server.PrincipalHandleByteSize {
conn.Close()
- return nil, nil, verror.BadProtocolf("invalid response from agent. (expected %d bytes, got %d)", server.PrincipalHandleByteSize, n)
+ return nil, nil, verror.Make(errInvalidResponse, ctx, server.PrincipalHandleByteSize, n)
}
return buf, conn, nil
}
@@ -84,7 +94,7 @@
// Typically this will be passed to a child process using cmd.ExtraFiles.
func (a *Agent) NewConnection(handle []byte) (*os.File, error) {
if len(handle) != server.PrincipalHandleByteSize {
- return nil, verror.BadArgf("Invalid key handle")
+ return nil, verror.Make(errInvalidKeyHandle, nil)
}
a.mu.Lock()
defer a.mu.Unlock()