mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-02 03:38:42 -07:00
Harmonize subject mapping error variable names
Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
This commit is contained in:
@@ -208,20 +208,20 @@ var (
|
||||
// ErrUnknownMappingDestinationFunction is returned when a subject mapping destination contains an unknown mustache-escaped mapping function.
|
||||
ErrUnknownMappingDestinationFunction = fmt.Errorf("%w: unknown function", ErrInvalidMappingDestination)
|
||||
|
||||
// ErrorMappingDestinationFunctionWildcardIndexOutOfRange is returned when the mapping destination function is passed an out of range wildcard index value for one of it's arguments
|
||||
ErrorMappingDestinationFunctionWildcardIndexOutOfRange = fmt.Errorf("%w: wildcard index out of range", ErrInvalidMappingDestination)
|
||||
// ErrMappingDestinationIndexOutOfRange is returned when the mapping destination function is passed an out of range wildcard index value for one of it's arguments
|
||||
ErrMappingDestinationIndexOutOfRange = fmt.Errorf("%w: wildcard index out of range", ErrInvalidMappingDestination)
|
||||
|
||||
// ErrorMappingDestinationFunctionNotEnoughArguments is returned when the mapping destination function is not passed enough arguments
|
||||
ErrorMappingDestinationFunctionNotEnoughArguments = fmt.Errorf("%w: not enough arguments passed to the function", ErrInvalidMappingDestination)
|
||||
// ErrMappingDestinationNotEnoughArgs is returned when the mapping destination function is not passed enough arguments
|
||||
ErrMappingDestinationNotEnoughArgs = fmt.Errorf("%w: not enough arguments passed to the function", ErrInvalidMappingDestination)
|
||||
|
||||
// ErrorMappingDestinationFunctionInvalidArgument is returned when the mapping destination function is passed and invalid argument
|
||||
ErrorMappingDestinationFunctionInvalidArgument = fmt.Errorf("%w: function argument is invalid or in the wrong format", ErrInvalidMappingDestination)
|
||||
// ErrMappingDestinationInvalidArg is returned when the mapping destination function is passed and invalid argument
|
||||
ErrMappingDestinationInvalidArg = fmt.Errorf("%w: function argument is invalid or in the wrong format", ErrInvalidMappingDestination)
|
||||
|
||||
// ErrorMappingDestinationFunctionTooManyArguments is returned when the mapping destination function is passed too many arguments
|
||||
ErrorMappingDestinationFunctionTooManyArguments = fmt.Errorf("%w: too many arguments passed to the function", ErrInvalidMappingDestination)
|
||||
// ErrMappingDestinationTooManyArgs is returned when the mapping destination function is passed too many arguments
|
||||
ErrMappingDestinationTooManyArgs = fmt.Errorf("%w: too many arguments passed to the function", ErrInvalidMappingDestination)
|
||||
|
||||
// ErrorMappingDestinationFunctionNotSupportedForImport is returned when you try to use a mapping function other than wildcard in a transform that needs to be reversible (i.e. an import)
|
||||
ErrorMappingDestinationFunctionNotSupportedForImport = fmt.Errorf("%w: the only mapping function allowed for import transforms is {{Wildcard()}}", ErrInvalidMappingDestination)
|
||||
// ErrMappingDestinationNotSupportedForImport is returned when you try to use a mapping function other than wildcard in a transform that needs to be reversible (i.e. an import)
|
||||
ErrMappingDestinationNotSupportedForImport = fmt.Errorf("%w: the only mapping function allowed for import transforms is {{Wildcard()}}", ErrInvalidMappingDestination)
|
||||
)
|
||||
|
||||
// mappingDestinationErr is a type of subject mapping destination error
|
||||
|
||||
@@ -110,13 +110,13 @@ func NewSubjectTransformWithStrict(src, dest string, strict bool) (*subjectTrans
|
||||
|
||||
if strict {
|
||||
if tranformType != NoTransform && tranformType != Wildcard {
|
||||
return nil, &mappingDestinationErr{token, ErrorMappingDestinationFunctionNotSupportedForImport}
|
||||
return nil, &mappingDestinationErr{token, ErrMappingDestinationNotSupportedForImport}
|
||||
}
|
||||
}
|
||||
|
||||
if npwcs == 0 {
|
||||
if tranformType != NoTransform {
|
||||
return nil, &mappingDestinationErr{token, ErrorMappingDestinationFunctionWildcardIndexOutOfRange}
|
||||
return nil, &mappingDestinationErr{token, ErrMappingDestinationIndexOutOfRange}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,7 +131,7 @@ func NewSubjectTransformWithStrict(src, dest string, strict bool) (*subjectTrans
|
||||
var stis []int
|
||||
for _, wildcardIndex := range transformArgWildcardIndexes {
|
||||
if wildcardIndex > npwcs {
|
||||
return nil, &mappingDestinationErr{fmt.Sprintf("%s: [%d]", token, wildcardIndex), ErrorMappingDestinationFunctionWildcardIndexOutOfRange}
|
||||
return nil, &mappingDestinationErr{fmt.Sprintf("%s: [%d]", token, wildcardIndex), ErrMappingDestinationIndexOutOfRange}
|
||||
}
|
||||
stis = append(stis, sti[wildcardIndex])
|
||||
}
|
||||
@@ -155,7 +155,7 @@ func NewSubjectTransformWithStrict(src, dest string, strict bool) (*subjectTrans
|
||||
}
|
||||
|
||||
if tranformType != NoTransform {
|
||||
return nil, &mappingDestinationErr{token, ErrorMappingDestinationFunctionWildcardIndexOutOfRange}
|
||||
return nil, &mappingDestinationErr{token, ErrMappingDestinationIndexOutOfRange}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,18 +191,18 @@ func getMappingFunctionArgs(functionRegEx *regexp.Regexp, token string) []string
|
||||
// Helper for mapping functions that take a wildcard index and an integer as arguments
|
||||
func transformIndexIntArgsHelper(token string, args []string, transformType int16) (int16, []int, int32, string, error) {
|
||||
if len(args) < 2 {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionNotEnoughArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationNotEnoughArgs}
|
||||
}
|
||||
if len(args) > 2 {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionTooManyArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationTooManyArgs}
|
||||
}
|
||||
i, err := strconv.Atoi(strings.Trim(args[0], " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
mappingFunctionIntArg, err := strconv.Atoi(strings.Trim(args[1], " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
|
||||
return transformType, []int{i}, int32(mappingFunctionIntArg), _EMPTY_, nil
|
||||
@@ -230,16 +230,16 @@ func indexPlaceHolders(token string) (int16, []int, int32, string, error) {
|
||||
args := getMappingFunctionArgs(wildcardMappingFunctionRegEx, token)
|
||||
if args != nil {
|
||||
if len(args) == 1 && args[0] == _EMPTY_ {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionNotEnoughArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationNotEnoughArgs}
|
||||
}
|
||||
if len(args) == 1 {
|
||||
tokenIndex, err := strconv.Atoi(strings.Trim(args[0], " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
return Wildcard, []int{tokenIndex}, -1, _EMPTY_, nil
|
||||
} else {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionTooManyArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationTooManyArgs}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -247,19 +247,19 @@ func indexPlaceHolders(token string) (int16, []int, int32, string, error) {
|
||||
args = getMappingFunctionArgs(partitionMappingFunctionRegEx, token)
|
||||
if args != nil {
|
||||
if len(args) < 2 {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionNotEnoughArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationNotEnoughArgs}
|
||||
}
|
||||
if len(args) >= 2 {
|
||||
mappingFunctionIntArg, err := strconv.Atoi(strings.Trim(args[0], " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
var numPositions = len(args[1:])
|
||||
tokenIndexes := make([]int, numPositions)
|
||||
for ti, t := range args[1:] {
|
||||
i, err := strconv.Atoi(strings.Trim(t, " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
tokenIndexes[ti] = i
|
||||
}
|
||||
@@ -296,17 +296,17 @@ func indexPlaceHolders(token string) (int16, []int, int32, string, error) {
|
||||
args = getMappingFunctionArgs(splitMappingFunctionRegEx, token)
|
||||
if args != nil {
|
||||
if len(args) < 2 {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionNotEnoughArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationNotEnoughArgs}
|
||||
}
|
||||
if len(args) > 2 {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionTooManyArguments}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationTooManyArgs}
|
||||
}
|
||||
i, err := strconv.Atoi(strings.Trim(args[0], " "))
|
||||
if err != nil {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token, ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
if strings.Contains(args[1], " ") || strings.Contains(args[1], tsep) {
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token: token, err: ErrorMappingDestinationFunctionInvalidArgument}
|
||||
return BadTransform, []int{}, -1, _EMPTY_, &mappingDestinationErr{token: token, err: ErrMappingDestinationInvalidArg}
|
||||
}
|
||||
|
||||
return Split, []int{i}, -1, args[1], nil
|
||||
|
||||
Reference in New Issue
Block a user