Skip to content

Preserve order of arg concatenation #1096

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions pkg/lib/configreader/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,55 +139,55 @@ func ErrorMustHavePrefix(provided string, prefix string) error {
}

func ErrorInvalidInterface(provided interface{}, allowed interface{}, allowedVals ...interface{}) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]interface{}{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidInterface,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidFloat64(provided float64, allowed float64, allowedVals ...float64) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]float64{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidFloat64,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidFloat32(provided float32, allowed float32, allowedVals ...float32) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]float32{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidFloat32,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidInt64(provided int64, allowed int64, allowedVals ...int64) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]int64{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidInt64,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidInt32(provided int32, allowed int32, allowedVals ...int32) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]int32{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidInt32,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidInt(provided int, allowed int, allowedVals ...int) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]int{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidInt,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
})
}

func ErrorInvalidStr(provided string, allowed string, allowedVals ...string) error {
allAllowedVals := append(allowedVals, allowed)
allAllowedVals := append([]string{allowed}, allowedVals...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidStr,
Message: fmt.Sprintf("invalid value (got %s, must be %s)", s.UserStr(provided), s.UserStrsOr(allAllowedVals)),
Expand Down Expand Up @@ -237,7 +237,7 @@ func ErrorNonStringKeyFound(key interface{}) error {
}

func ErrorInvalidPrimitiveType(provided interface{}, allowedType PrimitiveType, allowedTypes ...PrimitiveType) error {
allAllowedTypes := append(allowedTypes, allowedType)
allAllowedTypes := append([]PrimitiveType{allowedType}, allowedTypes...)
return errors.WithStack(&errors.Error{
Kind: ErrInvalidPrimitiveType,
Message: fmt.Sprintf("%s: invalid type (expected %s)", s.UserStr(provided), s.StrsOr(PrimitiveTypes(allAllowedTypes).StringList())),
Expand Down
4 changes: 2 additions & 2 deletions pkg/operator/endpoints/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ func ErrorPathParamRequired(param string) error {
}

func ErrorAnyQueryParamRequired(param string, params ...string) error {
allParams := append(params, param)
allParams := append([]string{param}, params...)
return errors.WithStack(&errors.Error{
Kind: ErrAnyQueryParamRequired,
Message: fmt.Sprintf("query params required: %s", s.UserStrsOr(allParams)),
})
}

func ErrorAnyPathParamRequired(param string, params ...string) error {
allParams := append(params, param)
allParams := append([]string{param}, params...)
return errors.WithStack(&errors.Error{
Kind: ErrAnyPathParamRequired,
Message: fmt.Sprintf("path params required: %s", s.UserStrsOr(allParams)),
Expand Down
4 changes: 2 additions & 2 deletions pkg/types/spec/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func ErrorDuplicateEndpoint(apiName string) error {
}

func ErrorSpecifyAllOrNone(val string, vals ...string) error {
allVals := append(vals, val)
allVals := append([]string{val}, vals...)
message := fmt.Sprintf("please specify all or none of %s", s.UserStrsAnd(allVals))
if len(allVals) == 2 {
message = fmt.Sprintf("please specify both %s and %s or neither of them", s.UserStr(allVals[0]), s.UserStr(allVals[1]))
Expand All @@ -115,7 +115,7 @@ func ErrorSpecifyAllOrNone(val string, vals ...string) error {
}

func ErrorOneOfPrerequisitesNotDefined(argName string, prerequisite string, prerequisites ...string) error {
allPrerequisites := append(prerequisites, prerequisite)
allPrerequisites := append([]string{prerequisite}, prerequisites...)
message := fmt.Sprintf("%s specified without specifying %s", s.UserStr(argName), s.UserStrsOr(allPrerequisites))

return errors.WithStack(&errors.Error{
Expand Down