-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
[IMPROVED] Subject transform validation and error reporting #4202
Conversation
As it was, any error in a weighted mapping would return a very unhelpfull error message. e.g. `nats-server: mappingtest.cfg:38:39: interface conversion: interface {} is []interface {}, not string` This was because the line `err := &configErr{tk, fmt.Sprintf("Error adding mapping for %q to %q : %v", subj, v.(string), err)}` would panic on the `v.(string)` since in weighted mapping that interface{} is actually a map[string]interface{} (since there's can be more than one mapping in weighted mappings). Now returns the actual error: e.g. `nats-server: mappingtest.cfg:40:3: Error adding mapping for "bla" : invalid mapping destination: wildcard index out of range in {{wildcard(1)}}` 2: improves subject transform checking and catches if the destination is using a mapping function and there are no partial wildcards in the source. Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM sans the length of that error.
server/subject_transform.go
Outdated
@@ -114,6 +114,12 @@ func NewSubjectTransformWithStrict(src, dest string, strict bool) (*subjectTrans | |||
} | |||
} | |||
|
|||
if npwcs == 0 { | |||
if tranformType != NoTransform { | |||
return nil, &mappingDestinationErr{token, ErrorMappingDestinationFunctionWildcardIndexOutOfRange} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got to be a shorter version of this no?
ErrorMappingDestinationFunctionWildcardIndexOutOfRange
server/subject_transform.go
Outdated
} | ||
|
||
if tranformType != NoTransform { | ||
return nil, &mappingDestinationErr{token, ErrorMappingDestinationFunctionWildcardIndexOutOfRange} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
Signed-off-by: Jean-Noël Moyne <jnmoyne@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
git pull --rebase origin main
)Changes proposed in this pull request:
1: Improves error reporting for weighted mappings:
As it was, any error in a weighted mapping would return a very unhelpfull error message.
e.g.
nats-server: mappingtest.cfg:38:39: interface conversion: interface {} is []interface {}, not string
This was because the line
err := &configErr{tk, fmt.Sprintf("Error adding mapping for %q to %q : %v", subj, v.(string), err)}
would panic on thev.(string)
since in weighted mapping that interface{} is actually a map[string]interface{} (since there's can be more than one mapping in weighted mappings).Now returns the actual error:
e.g.
nats-server: mappingtest.cfg:40:3: Error adding mapping for "bla" : invalid mapping destination: wildcard index out of range in {{wildcard(1)}}
2: improves subject transform checking and catches if the destination is using a mapping function and there are no partial wildcards in the source.