From d7b0469b8abec802f21aeda249d0d106f24a4600 Mon Sep 17 00:00:00 2001 From: Cosmos Nicolaou Date: Thu, 21 Mar 2024 10:31:44 -0700 Subject: [PATCH] . --- v23/flow/errors.go | 18 +++---- v23/flow/message/errors.go | 8 ++-- v23/naming/model.go | 10 ++-- v23/verror/pkgpath.go | 6 ++- v23/vom/dump.go | 8 +++- x/ref/lib/security/principal.go | 4 +- x/ref/runtime/internal/flow/conn/errors.go | 48 +++++++++---------- x/ref/runtime/internal/flow/manager/errors.go | 33 +++++++++---- .../internal/naming/namespace/resolve.go | 6 ++- x/ref/runtime/internal/rpc/client.go | 37 ++++++++++---- x/ref/runtime/internal/rpc/sort_endpoints.go | 6 ++- x/ref/runtime/internal/rpc/test/retry_test.go | 6 ++- 12 files changed, 119 insertions(+), 71 deletions(-) diff --git a/v23/flow/errors.go b/v23/flow/errors.go index 4d708beda..f99eb5b9c 100644 --- a/v23/flow/errors.go +++ b/v23/flow/errors.go @@ -11,13 +11,13 @@ import "v.io/v23/verror" // These were previously defined in errors.vdl using the ID values // below rather than the more conventional Err. var ( - ErrAuth = verror.NewID("Auth") - ErrNotTrusted = verror.NewID("NotTrusted") - ErrNetwork = verror.NewID("Network") - ErrDialFailed = verror.NewID("DialFailed") - ErrResolveFailed = verror.NewID("ResolveFailed") - ErrProxy = verror.NewID("Proxy") - ErrBadArg = verror.NewID("BadArg") - ErrBadState = verror.NewID("BadState") - ErrAborted = verror.NewID("Aborted") + ErrAuth = verror.NewID("v.io/v23/flow.Auth") + ErrNotTrusted = verror.NewID("v.io/v23/flow.NotTrusted") + ErrNetwork = verror.NewID("v.io/v23/flow.Network") + ErrDialFailed = verror.NewID("v.io/v23/flow.DialFailed") + ErrResolveFailed = verror.NewID("v.io/v23/flow.ResolveFailed") + ErrProxy = verror.NewID("v.io/v23/flow.Proxy") + ErrBadArg = verror.NewID("v.io/v23/flow.BadArg") + ErrBadState = verror.NewID("v.io/v23/flow.BadState") + ErrAborted = verror.NewID("v.io/v23/flow.Aborted") ) diff --git a/v23/flow/message/errors.go b/v23/flow/message/errors.go index 8d016b45a..74878e75a 100644 --- a/v23/flow/message/errors.go +++ b/v23/flow/message/errors.go @@ -12,10 +12,10 @@ import ( ) var ( - ErrInvalidMsg = verror.NewID("InvalidMsg") - ErrInvalidSetupOption = verror.NewID("InvalidSetupOption") - ErrUnknownMsg = verror.NewID("UnknownMsg") - ErrMissingBlessings = verror.NewID("MissingBlessings") + ErrInvalidMsg = verror.NewID("v.io/v23/flow/messages.InvalidMsg") + ErrInvalidSetupOption = verror.NewID("v.io/v23/flow/messages.InvalidSetupOption") + ErrUnknownMsg = verror.NewID("v.io/v23/flow/messages.UnknownMsg") + ErrMissingBlessings = verror.NewID("v.io/v23/flow/messages.MissingBlessings") ) // NewErrInvalidMsg creates an instance ErrInvalidMsg with the specified parameters which can be diff --git a/v23/naming/model.go b/v23/naming/model.go index 54be7cca0..ce0275465 100644 --- a/v23/naming/model.go +++ b/v23/naming/model.go @@ -13,11 +13,11 @@ const ( ) var ( - ErrNameExists = verror.NewID("nameExists") - ErrNoSuchName = verror.NewID("nameDoesntExist") - ErrNoSuchNameRoot = verror.NewID("rootNameDoesntExist") - ErrResolutionDepthExceeded = verror.NewID("resolutionDepthExceeded") - ErrNoMountTable = verror.NewID("noMounttable") + ErrNameExists = verror.NewID("v.io/v23/naming.nameExists") + ErrNoSuchName = verror.NewID("v.io/v23/naming.nameDoesntExist") + ErrNoSuchNameRoot = verror.NewID("v.io/v23/naming.rootNameDoesntExist") + ErrResolutionDepthExceeded = verror.NewID("v.io/v23/naming.resolutionDepthExceeded") + ErrNoMountTable = verror.NewID("v.io/v23/naming.noMounttable") ) // Names returns the servers represented by MountEntry as names, including diff --git a/v23/verror/pkgpath.go b/v23/verror/pkgpath.go index b921f83a1..f09a189a9 100644 --- a/v23/verror/pkgpath.go +++ b/v23/verror/pkgpath.go @@ -110,8 +110,12 @@ func ensurePackagePath(id ID) ID { if strings.Contains(sid, ".") && sid[0] != '.' { return id } - _, file, _, _ := runtime.Caller(2) + _, file, _, ok := runtime.Caller(2) pkg := pkgPathCache.pkgPath(file) + if ok && file == "" { + // See https://github.com/golang/go/issues/64520 + panic("verror.NewID was called to initalize a global variable, move that initialization to an init function or specify the full package path in the ID\nNOTE that the stack trace shown below is not useful since its incorrect contents are the cause of the problem, see https://github.com/golang/go/issues/64520") + } if len(pkg) == 0 { return id } diff --git a/v23/vom/dump.go b/v23/vom/dump.go index a163a45a4..252617826 100644 --- a/v23/vom/dump.go +++ b/v23/vom/dump.go @@ -15,10 +15,14 @@ import ( ) var ( - errDumperClosed = verror.NewID("errDumperClosed") - errDumperFlushed = verror.NewID("errDumperFlushed") + errDumperClosed, errDumperFlushed verror.IDAction ) +func init() { + errDumperClosed = verror.NewID("errDumperClosed") + errDumperFlushed = verror.NewID("errDumperFlushed") +} + // Dump returns a human-readable dump of the given vom data, in the default // string format. func Dump(data []byte) (string, error) { diff --git a/x/ref/lib/security/principal.go b/x/ref/lib/security/principal.go index 62f7dad88..2ec790546 100644 --- a/x/ref/lib/security/principal.go +++ b/x/ref/lib/security/principal.go @@ -17,9 +17,9 @@ import ( var ( // ErrBadPassphrase is a possible return error from LoadPersistentPrincipal() - ErrBadPassphrase = verror.NewID("errBadPassphrase") + ErrBadPassphrase = verror.NewID("v.io/x/ref/lib/security.errBadPassphrase") // ErrPassphraseRequired is a possible return error from LoadPersistentPrincipal() - ErrPassphraseRequired = verror.NewID("errPassphraseRequired") + ErrPassphraseRequired = verror.NewID("v.io/x/ref/lib/security.errPassphraseRequired") ) // NewPrincipal mints a new private (ecdsa) key and generates a principal diff --git a/x/ref/runtime/internal/flow/conn/errors.go b/x/ref/runtime/internal/flow/conn/errors.go index a83cfce9a..cefd7d5f6 100644 --- a/x/ref/runtime/internal/flow/conn/errors.go +++ b/x/ref/runtime/internal/flow/conn/errors.go @@ -9,28 +9,28 @@ import "v.io/v23/verror" // These were previously defined in errors.vdl using the ID values // below rather than the more conventional Err. var ( - ErrMissingSetupOption = verror.NewID("MissingSetupOption") - ErrUnexpectedMsg = verror.NewID("UnexpectedMsg") - ErrConnectionClosed = verror.NewID("ConnectionClosed") - ErrRemoteError = verror.NewID("RemoteError") - ErrSend = verror.NewID("Send") - ErrRecv = verror.NewID("Recv") - ErrCounterOverflow = verror.NewID("CounterOverflow") - ErrBlessingsFlowClosed = verror.NewID("BlessingsFlowClosed") - ErrInvalidChannelBinding = verror.NewID("InvalidChannelBinding") - ErrNoPublicKey = verror.NewID("NoPublicKey") - ErrDialingNonServer = verror.NewID("DialingNonServer") - ErrAcceptorBlessingsMissing = verror.NewID("AcceptorBlessingsMissing") - ErrDialerBlessingsMissing = verror.NewID("DialerBlessingsMissing") - ErrBlessingsNotBound = verror.NewID("BlessingsNotBound") - ErrInvalidPeerFlow = verror.NewID("InvalidPeerFlow") - ErrChannelTimeout = verror.NewID("ChannelTimeout") - ErrCannotDecryptBlessings = verror.NewID("CannotDecryptBlessings") - ErrCannotDecryptDischarges = verror.NewID("CannotDecryptDischarges") - ErrCannotEncryptBlessings = verror.NewID("CannotEncryptBlessings") - ErrCannotEncryptDischarges = verror.NewID("CannotEncryptDischarges") - ErrNoCrypter = verror.NewID("NoCrypter") - ErrNoPrivateKey = verror.NewID("NoPrivateKey") - ErrIdleConnKilled = verror.NewID("IdleConnKilled") - ErrRPCVersionMismatch = verror.NewID("RPCVersionMismatch") + ErrMissingSetupOption = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.MissingSetupOption") + ErrUnexpectedMsg = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.UnexpectedMsg") + ErrConnectionClosed = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.ConnectionClosed") + ErrRemoteError = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.RemoteError") + ErrSend = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.Send") + ErrRecv = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.Recv") + ErrCounterOverflow = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.CounterOverflow") + ErrBlessingsFlowClosed = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.BlessingsFlowClosed") + ErrInvalidChannelBinding = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.InvalidChannelBinding") + ErrNoPublicKey = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.NoPublicKey") + ErrDialingNonServer = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.DialingNonServer") + ErrAcceptorBlessingsMissing = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.AcceptorBlessingsMissing") + ErrDialerBlessingsMissing = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.DialerBlessingsMissing") + ErrBlessingsNotBound = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.BlessingsNotBound") + ErrInvalidPeerFlow = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.InvalidPeerFlow") + ErrChannelTimeout = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.ChannelTimeout") + ErrCannotDecryptBlessings = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.CannotDecryptBlessings") + ErrCannotDecryptDischarges = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.CannotDecryptDischarges") + ErrCannotEncryptBlessings = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.CannotEncryptBlessings") + ErrCannotEncryptDischarges = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.CannotEncryptDischarges") + ErrNoCrypter = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.NoCrypter") + ErrNoPrivateKey = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.NoPrivateKey") + ErrIdleConnKilled = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.IdleConnKilled") + ErrRPCVersionMismatch = verror.NewID("v.io/x/ref/runtime/internal/flow/conn.RPCVersionMismatch") ) diff --git a/x/ref/runtime/internal/flow/manager/errors.go b/x/ref/runtime/internal/flow/manager/errors.go index b4cac9645..ba4ed9635 100644 --- a/x/ref/runtime/internal/flow/manager/errors.go +++ b/x/ref/runtime/internal/flow/manager/errors.go @@ -9,14 +9,27 @@ import "v.io/v23/verror" var ( // These were defined in errors.vdl using the ID values // below rather than the more conventional Err. - errUnknownProtocol = verror.NewID("UnknownProtocol") - errManagerClosed = verror.NewID("ManagerClosed") - errAcceptFailed = verror.NewID("AcceptFailed") - errCacheClosed = verror.NewID("CacheClosed") - errConnKilledToFreeResources = verror.NewID("ConnKilledToFreeResources") - errInvalidProxyResponse = verror.NewID("InvalidProxyResponse") - errListeningWithNullRid = verror.NewID("ListeningWithNullRid") - errProxyResponse = verror.NewID("ProxyResponse") - errNoBlessingsForPeer = verror.NewID("NoBlessingsForPeer") - errConnNotInCache = verror.NewID("ConnNotInCache") + errUnknownProtocol verror.IDAction + errManagerClosed verror.IDAction + errAcceptFailed verror.IDAction + errCacheClosed verror.IDAction + errConnKilledToFreeResources verror.IDAction + errInvalidProxyResponse verror.IDAction + errListeningWithNullRid verror.IDAction + errProxyResponse verror.IDAction + errNoBlessingsForPeer verror.IDAction + errConnNotInCache verror.IDAction ) + +func init() { + errUnknownProtocol = verror.NewID("UnknownProtocol") + errManagerClosed = verror.NewID("ManagerClosed") + errAcceptFailed = verror.NewID("AcceptFailed") + errCacheClosed = verror.NewID("CacheClosed") + errConnKilledToFreeResources = verror.NewID("ConnKilledToFreeResources") + errInvalidProxyResponse = verror.NewID("InvalidProxyResponse") + errListeningWithNullRid = verror.NewID("ListeningWithNullRid") + errProxyResponse = verror.NewID("ProxyResponse") + errNoBlessingsForPeer = verror.NewID("NoBlessingsForPeer") + errConnNotInCache = verror.NewID("ConnNotInCache") +} diff --git a/x/ref/runtime/internal/naming/namespace/resolve.go b/x/ref/runtime/internal/naming/namespace/resolve.go index fb1a26f8a..edb50874e 100644 --- a/x/ref/runtime/internal/naming/namespace/resolve.go +++ b/x/ref/runtime/internal/naming/namespace/resolve.go @@ -17,9 +17,11 @@ import ( "v.io/v23/verror" ) -var ( +var errNoServers verror.IDAction + +func init() { errNoServers = verror.NewIDAction("errNoServers", verror.NoRetry) -) +} // resolveAgainstMountTable asks each server in e.Servers that might be a mounttable to resolve e.Name. The requests // are parallelized by the client rpc code. diff --git a/x/ref/runtime/internal/rpc/client.go b/x/ref/runtime/internal/rpc/client.go index a99d0a215..e4d221038 100644 --- a/x/ref/runtime/internal/rpc/client.go +++ b/x/ref/runtime/internal/rpc/client.go @@ -35,21 +35,38 @@ const ( ) var ( - errClientCloseAlreadyCalled = verror.NewID("errCloseAlreadyCalled") + errClientCloseAlreadyCalled verror.IDAction + errClientFinishAlreadyCalled verror.IDAction + errRequestEncoding verror.IDAction + errArgEncoding verror.IDAction + errResponseDecoding verror.IDAction + errResultDecoding verror.IDAction + errRemainingStreamResults verror.IDAction + errPeerAuthorizeFailed verror.IDAction + errTypeFlowFailure verror.IDAction + + // These were originally defined in vdl and hence the same IDs that + // vdl would generate must be used here to ensure backwards compatibility. + errBadNumInputArgs verror.IDAction + errBadInputArg verror.IDAction +) + +func init() { + errClientCloseAlreadyCalled = verror.NewID("errCloseAlreadyCalled") errClientFinishAlreadyCalled = verror.NewID("errFinishAlreadyCalled") - errRequestEncoding = verror.NewID("errRequestEncoding") - errArgEncoding = verror.NewID("errArgEncoding") - errResponseDecoding = verror.NewID("errResponseDecoding") - errResultDecoding = verror.NewID("errResultDecoding") - errRemainingStreamResults = verror.NewID("errRemaingStreamResults") - errPeerAuthorizeFailed = verror.NewID("errPeerAuthorizedFailed") - errTypeFlowFailure = verror.NewID("errTypeFlowFailure") + errRequestEncoding = verror.NewID("errRequestEncoding") + errArgEncoding = verror.NewID("errArgEncoding") + errResponseDecoding = verror.NewID("errResponseDecoding") + errResultDecoding = verror.NewID("errResultDecoding") + errRemainingStreamResults = verror.NewID("errRemaingStreamResults") + errPeerAuthorizeFailed = verror.NewID("errPeerAuthorizedFailed") + errTypeFlowFailure = verror.NewID("errTypeFlowFailure") // These were originally defined in vdl and hence the same IDs that // vdl would generate must be used here to ensure backwards compatibility. errBadNumInputArgs = verror.NewID("badNumInputArgs") - errBadInputArg = verror.NewID("badInputArg") -) + errBadInputArg = verror.NewID("badInputArg") +} func preferNonTimeout(curr, prev error) error { if prev != nil && errors.Is(curr, verror.ErrTimeout) { diff --git a/x/ref/runtime/internal/rpc/sort_endpoints.go b/x/ref/runtime/internal/rpc/sort_endpoints.go index cd6d52cf0..5ed3d0c76 100644 --- a/x/ref/runtime/internal/rpc/sort_endpoints.go +++ b/x/ref/runtime/internal/rpc/sort_endpoints.go @@ -18,10 +18,14 @@ import ( ) var ( - errNoCompatibleServers = verror.NewID("errNoComaptibleServers") + errNoCompatibleServers verror.IDAction defaultPreferredProtocolOrder = mkProtocolRankMap([]string{"unixfd", "wsh", "tcp4", "tcp", "*"}) ) +func init() { + errNoCompatibleServers = verror.NewID("errNoComaptibleServers") +} + type serverLocality int const ( diff --git a/x/ref/runtime/internal/rpc/test/retry_test.go b/x/ref/runtime/internal/rpc/test/retry_test.go index 36f4b64d3..ba5626da0 100644 --- a/x/ref/runtime/internal/rpc/test/retry_test.go +++ b/x/ref/runtime/internal/rpc/test/retry_test.go @@ -16,7 +16,11 @@ import ( "v.io/x/ref/test" ) -var errRetryThis = verror.NewIDAction("retry_test.retryThis", verror.RetryBackoff) +var errRetryThis verror.IDAction + +func init() { + errRetryThis = verror.NewIDAction("retry_test.retryThis", verror.RetryBackoff) +} type retryServer struct { called int // number of times TryAgain has been called