2023-03-28 18:39:22 +00:00
// Copyright (c) HashiCorp, Inc.
2023-08-11 13:12:13 +00:00
// SPDX-License-Identifier: BUSL-1.1
2023-03-28 18:39:22 +00:00
2017-09-01 22:02:50 +00:00
package structs
import (
"errors"
"strings"
)
const (
2024-05-14 21:33:34 +00:00
errNoLeader = "No cluster leader"
errNoDCPath = "No path to datacenter"
errDCNotAvailable = "Remote DC has no server currently reachable"
errNoServers = "No known Consul servers"
errNotReadyForConsistentReads = "Not ready to serve consistent reads"
errSegmentsNotSupported = "Network segments are not supported in this version of Consul"
errRPCRateExceeded = "RPC rate limit exceeded"
errServiceNotFound = "Service not found: "
errQueryNotFound = "Query not found"
errLeaderNotTracked = "Raft leader not found in server lookup mapping"
errConnectNotEnabled = "Connect must be enabled in order to use this endpoint"
errRateLimited = "Rate limit reached, try again later" // Note: we depend on this error message in the gRPC ConnectCA.Sign endpoint (see: isRateLimitError).
errNotPrimaryDatacenter = "not the primary datacenter"
errStateReadOnly = "CA Provider State is read-only"
2024-08-13 22:53:48 +00:00
errSamenessGroupNotFound = "Sameness Group not found"
2024-05-14 21:33:34 +00:00
errSamenessGroupMustBeDefaultForFailover = "Sameness Group must have DefaultForFailover set to true in order to use this endpoint"
2017-09-01 22:02:50 +00:00
)
var (
2024-05-14 21:33:34 +00:00
ErrNoLeader = errors . New ( errNoLeader )
ErrNoDCPath = errors . New ( errNoDCPath )
ErrNoServers = errors . New ( errNoServers )
ErrNotReadyForConsistentReads = errors . New ( errNotReadyForConsistentReads )
ErrSegmentsNotSupported = errors . New ( errSegmentsNotSupported )
ErrRPCRateExceeded = errors . New ( errRPCRateExceeded )
ErrDCNotAvailable = errors . New ( errDCNotAvailable )
ErrQueryNotFound = errors . New ( errQueryNotFound )
ErrLeaderNotTracked = errors . New ( errLeaderNotTracked )
ErrConnectNotEnabled = errors . New ( errConnectNotEnabled )
ErrRateLimited = errors . New ( errRateLimited ) // Note: we depend on this error message in the gRPC ConnectCA.Sign endpoint (see: isRateLimitError).
ErrNotPrimaryDatacenter = errors . New ( errNotPrimaryDatacenter )
ErrStateReadOnly = errors . New ( errStateReadOnly )
2024-08-13 22:53:48 +00:00
ErrSamenessGroupNotFound = errors . New ( errSamenessGroupNotFound )
2024-05-14 21:33:34 +00:00
ErrSamenessGroupMustBeDefaultForFailover = errors . New ( errSamenessGroupMustBeDefaultForFailover )
2017-09-01 22:02:50 +00:00
)
2020-06-30 22:03:31 +00:00
func IsErrNoDCPath ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errNoDCPath )
}
2020-07-01 00:49:13 +00:00
func IsErrQueryNotFound ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errQueryNotFound )
}
2017-10-10 22:19:50 +00:00
func IsErrNoLeader ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errNoLeader )
}
2017-09-01 22:02:50 +00:00
func IsErrRPCRateExceeded ( err error ) bool {
2017-10-10 22:19:50 +00:00
return err != nil && strings . Contains ( err . Error ( ) , errRPCRateExceeded )
2017-09-01 22:02:50 +00:00
}
2019-01-07 14:39:23 +00:00
2024-08-13 22:53:48 +00:00
func IsErrSamenessGroupNotFound ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errSamenessGroupNotFound )
}
2024-05-14 21:33:34 +00:00
func IsErrSamenessGroupMustBeDefaultForFailover ( err error ) bool {
return err != nil && strings . Contains ( err . Error ( ) , errSamenessGroupMustBeDefaultForFailover )
}