1 // pubsubplus-go-client 2 // 3 // Copyright 2021-2024 Solace Corporation. All rights reserved. 4 // 5 // Licensed under the Apache License, Version 2.0 (the "License"); 6 // you may not use this file except in compliance with the License. 7 // You may obtain a copy of the License at 8 // 9 // http://www.apache.org/licenses/LICENSE-2.0 10 // 11 // Unless required by applicable law or agreed to in writing, software 12 // distributed under the License is distributed on an "AS IS" BASIS, 13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 // See the License for the specific language governing permissions and 15 // limitations under the License. 16 17 package solace 18 19 import "solace.dev/go/messaging/pkg/solace/subcode" 20 21 // A solaceError struct used as a basis for all wrapping errors. 22 type solaceError struct { 23 message string 24 wrapped error 25 } 26 27 // setErrorInfo will set the information on the error. 28 func (err *solaceError) setErrorInfo(message string, wrapped error) { 29 err.message = message 30 err.wrapped = wrapped 31 } 32 33 // Error is an error returned from the API. 34 type Error interface { 35 error 36 setErrorInfo(message string, wrapped error) 37 } 38 39 // Error returns the error message. 40 func (err *solaceError) Error() string { 41 return err.message 42 } 43 44 // Unwrap returns the wrapped error. 45 func (err *solaceError) Unwrap() error { 46 return err.wrapped 47 } 48 49 // NativeError is a struct that stores the error message and subcode for the error message. 50 type NativeError struct { 51 message string 52 subcode subcode.Code 53 } 54 55 // Error returns the error message from solace.NativeError. 56 func (err *NativeError) Error() string { 57 return err.message 58 } 59 60 // SubCode returns the subcode associated with the specified error, otherwise SubCodeNone if no subcode is relevant. 61 func (err *NativeError) SubCode() subcode.Code { 62 return err.subcode 63 } 64 65 // NewNativeError returns a new solace.NativeError with the given message and subcode when applicable. 66 func NewNativeError(message string, subcode subcode.Code) *NativeError { 67 return &NativeError{ 68 message: message, 69 subcode: subcode, 70 } 71 } 72 73 // AuthenticationError indicates an authentication related error occurred when connecting to a remote event broker. 74 // The pointer type *AuthenticationError is returned. 75 type AuthenticationError struct { 76 solaceError 77 } 78 79 // IllegalStateError indicates an invalid state occurred when performing an action. 80 // The pointer type *IllegalStateError is returned. 81 type IllegalStateError struct { 82 solaceError 83 } 84 85 // IllegalArgumentError indicates an invalid argument was passed to a function. 86 // The pointer type *IllegalArgumentError is returned. 87 type IllegalArgumentError struct { 88 solaceError 89 } 90 91 // InvalidConfigurationError indicates that a specified configuration is invalid. 92 // These errors are returned by the Build functions of a builder. 93 // The pointer type *InvalidConfigurationError is returned. 94 type InvalidConfigurationError struct { 95 solaceError 96 } 97 98 // PublisherOverflowError indicates when publishing has stopped due to 99 // internal buffer limits. 100 // The pointer type *PublisherOverflowError is returned. 101 type PublisherOverflowError struct { 102 solaceError 103 } 104 105 // IncompleteMessageDeliveryError indicates that some messages were not delivered. 106 // The pointer type *IncompleteMessageDeliveryError is returned. 107 type IncompleteMessageDeliveryError struct { 108 solaceError 109 } 110 111 // ServiceUnreachableError indicates that a remote service connection could not be established. 112 // The pointer type *ServiceUnreachableError is returned. 113 type ServiceUnreachableError struct { 114 solaceError 115 } 116 117 // TimeoutError indicates that a timeout error occurred. 118 // The pointer type *TimeoutError is returned. 119 type TimeoutError struct { 120 solaceError 121 } 122 123 // MessageReplayError indicates 124 type MessageReplayError struct { 125 solaceError 126 } 127 128 // NewError returns a new Solace error with the specified message and wrapped error. 129 func NewError(err Error, message string, wrapped error) Error { 130 err.setErrorInfo(message, wrapped) 131 return err 132 } 133