From 902e95bd3bbe44737262616ad4e9829c81d5d6ca Mon Sep 17 00:00:00 2001 From: Sylvain Rabot Date: Sat, 24 Dec 2022 16:14:34 +0400 Subject: [PATCH] Create a generic "nats" error Signed-off-by: Sylvain Rabot --- nats.go | 99 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/nats.go b/nats.go index a5e2e4a4b..6326d877c 100644 --- a/nats.go +++ b/nats.go @@ -90,55 +90,56 @@ const ( // Errors var ( - ErrConnectionClosed = errors.New("nats: connection closed") - ErrConnectionDraining = errors.New("nats: connection draining") - ErrDrainTimeout = errors.New("nats: draining connection timed out") - ErrConnectionReconnecting = errors.New("nats: connection reconnecting") - ErrSecureConnRequired = errors.New("nats: secure connection required") - ErrSecureConnWanted = errors.New("nats: secure connection not available") - ErrBadSubscription = errors.New("nats: invalid subscription") - ErrTypeSubscription = errors.New("nats: invalid subscription type") - ErrBadSubject = errors.New("nats: invalid subject") - ErrBadQueueName = errors.New("nats: invalid queue name") - ErrSlowConsumer = errors.New("nats: slow consumer, messages dropped") - ErrTimeout = errors.New("nats: timeout") - ErrBadTimeout = errors.New("nats: timeout invalid") - ErrAuthorization = errors.New("nats: authorization violation") - ErrAuthExpired = errors.New("nats: authentication expired") - ErrAuthRevoked = errors.New("nats: authentication revoked") - ErrAccountAuthExpired = errors.New("nats: account authentication expired") - ErrNoServers = errors.New("nats: no servers available for connection") - ErrJsonParse = errors.New("nats: connect message, json parse error") - ErrChanArg = errors.New("nats: argument needs to be a channel type") - ErrMaxPayload = errors.New("nats: maximum payload exceeded") - ErrMaxMessages = errors.New("nats: maximum messages delivered") - ErrSyncSubRequired = errors.New("nats: illegal call on an async subscription") - ErrMultipleTLSConfigs = errors.New("nats: multiple tls.Configs not allowed") - ErrNoInfoReceived = errors.New("nats: protocol exception, INFO not received") - ErrReconnectBufExceeded = errors.New("nats: outbound buffer limit exceeded") - ErrInvalidConnection = errors.New("nats: invalid connection") - ErrInvalidMsg = errors.New("nats: invalid message or message nil") - ErrInvalidArg = errors.New("nats: invalid argument") - ErrInvalidContext = errors.New("nats: invalid context") - ErrNoDeadlineContext = errors.New("nats: context requires a deadline") - ErrNoEchoNotSupported = errors.New("nats: no echo option not supported by this server") - ErrClientIDNotSupported = errors.New("nats: client ID not supported by this server") - ErrUserButNoSigCB = errors.New("nats: user callback defined without a signature handler") - ErrNkeyButNoSigCB = errors.New("nats: nkey defined without a signature handler") - ErrNoUserCB = errors.New("nats: user callback not defined") - ErrNkeyAndUser = errors.New("nats: user callback and nkey defined") - ErrNkeysNotSupported = errors.New("nats: nkeys not supported by the server") - ErrStaleConnection = errors.New("nats: " + STALE_CONNECTION) - ErrTokenAlreadySet = errors.New("nats: token and token handler both set") - ErrMsgNotBound = errors.New("nats: message is not bound to subscription/connection") - ErrMsgNoReply = errors.New("nats: message does not have a reply") - ErrClientIPNotSupported = errors.New("nats: client IP not supported by this server") - ErrDisconnected = errors.New("nats: server is disconnected") - ErrHeadersNotSupported = errors.New("nats: headers not supported by this server") - ErrBadHeaderMsg = errors.New("nats: message could not decode headers") - ErrNoResponders = errors.New("nats: no responders available for request") - ErrMaxConnectionsExceeded = errors.New("nats: server maximum connections exceeded") - ErrConnectionNotTLS = errors.New("nats: connection is not tls") + ErrNats = errors.New("nats") + ErrConnectionClosed = fmt.Errorf("%w: connection closed", ErrNats) + ErrConnectionDraining = fmt.Errorf("%w: connection draining", ErrNats) + ErrDrainTimeout = fmt.Errorf("%w: draining connection timed out", ErrNats) + ErrConnectionReconnecting = fmt.Errorf("%w: connection reconnecting", ErrNats) + ErrSecureConnRequired = fmt.Errorf("%w: secure connection required", ErrNats) + ErrSecureConnWanted = fmt.Errorf("%w: secure connection not available", ErrNats) + ErrBadSubscription = fmt.Errorf("%w: invalid subscription", ErrNats) + ErrTypeSubscription = fmt.Errorf("%w: invalid subscription type", ErrNats) + ErrBadSubject = fmt.Errorf("%w: invalid subject", ErrNats) + ErrBadQueueName = fmt.Errorf("%w: invalid queue name", ErrNats) + ErrSlowConsumer = fmt.Errorf("%w: slow consumer, messages dropped", ErrNats) + ErrTimeout = fmt.Errorf("%w: timeout", ErrNats) + ErrBadTimeout = fmt.Errorf("%w: timeout invalid", ErrNats) + ErrAuthorization = fmt.Errorf("%w: authorization violation", ErrNats) + ErrAuthExpired = fmt.Errorf("%w: authentication expired", ErrNats) + ErrAuthRevoked = fmt.Errorf("%w: authentication revoked", ErrNats) + ErrAccountAuthExpired = fmt.Errorf("%w: account authentication expired", ErrNats) + ErrNoServers = fmt.Errorf("%w: no servers available for connection", ErrNats) + ErrJsonParse = fmt.Errorf("%w: connect message, json parse error", ErrNats) + ErrChanArg = fmt.Errorf("%w: argument needs to be a channel type", ErrNats) + ErrMaxPayload = fmt.Errorf("%w: maximum payload exceeded", ErrNats) + ErrMaxMessages = fmt.Errorf("%w: maximum messages delivered", ErrNats) + ErrSyncSubRequired = fmt.Errorf("%w: illegal call on an async subscription", ErrNats) + ErrMultipleTLSConfigs = fmt.Errorf("%w: multiple tls.Configs not allowed", ErrNats) + ErrNoInfoReceived = fmt.Errorf("%w: protocol exception, INFO not received", ErrNats) + ErrReconnectBufExceeded = fmt.Errorf("%w: outbound buffer limit exceeded", ErrNats) + ErrInvalidConnection = fmt.Errorf("%w: invalid connection", ErrNats) + ErrInvalidMsg = fmt.Errorf("%w: invalid message or message nil", ErrNats) + ErrInvalidArg = fmt.Errorf("%w: invalid argument", ErrNats) + ErrInvalidContext = fmt.Errorf("%w: invalid context", ErrNats) + ErrNoDeadlineContext = fmt.Errorf("%w: context requires a deadline", ErrNats) + ErrNoEchoNotSupported = fmt.Errorf("%w: no echo option not supported by this server", ErrNats) + ErrClientIDNotSupported = fmt.Errorf("%w: client ID not supported by this server", ErrNats) + ErrUserButNoSigCB = fmt.Errorf("%w: user callback defined without a signature handler", ErrNats) + ErrNkeyButNoSigCB = fmt.Errorf("%w: nkey defined without a signature handler", ErrNats) + ErrNoUserCB = fmt.Errorf("%w: user callback not defined", ErrNats) + ErrNkeyAndUser = fmt.Errorf("%w: user callback and nkey defined", ErrNats) + ErrNkeysNotSupported = fmt.Errorf("%w: nkeys not supported by the server", ErrNats) + ErrStaleConnection = fmt.Errorf("%w: "+STALE_CONNECTION, ErrNats) + ErrTokenAlreadySet = fmt.Errorf("%w: token and token handler both set", ErrNats) + ErrMsgNotBound = fmt.Errorf("%w: message is not bound to subscription/connection", ErrNats) + ErrMsgNoReply = fmt.Errorf("%w: message does not have a reply", ErrNats) + ErrClientIPNotSupported = fmt.Errorf("%w: client IP not supported by this server", ErrNats) + ErrDisconnected = fmt.Errorf("%w: server is disconnected", ErrNats) + ErrHeadersNotSupported = fmt.Errorf("%w: headers not supported by this server", ErrNats) + ErrBadHeaderMsg = fmt.Errorf("%w: message could not decode headers", ErrNats) + ErrNoResponders = fmt.Errorf("%w: no responders available for request", ErrNats) + ErrMaxConnectionsExceeded = fmt.Errorf("%w: server maximum connections exceeded", ErrNats) + ErrConnectionNotTLS = fmt.Errorf("%w: connection is not tls", ErrNats) ) func init() {