{"record":{"id":"c9adf520d4430350","repo":"nats-io/nats-server","slug":"invalid-mapping-destination-too-many-arguments-pa","errorCode":null,"errorMessage":"invalid mapping destination: too many arguments passed to the function","messagePattern":"invalid mapping destination: too many arguments passed to the function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":247,"sourceCode":"\tErrInvalidMappingDestinationSubject = fmt.Errorf(\"%w: invalid transform\", ErrInvalidMappingDestination)\n\n\t// ErrMappingDestinationNotUsingAllWildcards is used to error on a transform destination not using all of the token wildcards\n\tErrMappingDestinationNotUsingAllWildcards = fmt.Errorf(\"%w: not using all of the token wildcard(s)\", ErrInvalidMappingDestination)\n\n\t// ErrUnknownMappingDestinationFunction is returned when a subject mapping destination contains an unknown mustache-escaped mapping function.\n\tErrUnknownMappingDestinationFunction = fmt.Errorf(\"%w: unknown function\", ErrInvalidMappingDestination)\n\n\t// ErrMappingDestinationIndexOutOfRange is returned when the mapping destination function is passed an out of range wildcard index value for one of it's arguments\n\tErrMappingDestinationIndexOutOfRange = fmt.Errorf(\"%w: wildcard index out of range\", ErrInvalidMappingDestination)\n\n\t// ErrMappingDestinationNotEnoughArgs is returned when the mapping destination function is not passed enough arguments\n\tErrMappingDestinationNotEnoughArgs = fmt.Errorf(\"%w: not enough arguments passed to the function\", ErrInvalidMappingDestination)\n\n\t// ErrMappingDestinationInvalidArg is returned when the mapping destination function is passed and invalid argument\n\tErrMappingDestinationInvalidArg = fmt.Errorf(\"%w: function argument is invalid or in the wrong format\", ErrInvalidMappingDestination)\n\n\t// ErrMappingDestinationTooManyArgs is returned when the mapping destination function is passed too many arguments\n\tErrMappingDestinationTooManyArgs = fmt.Errorf(\"%w: too many arguments passed to the function\", ErrInvalidMappingDestination)\n\n\t// 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)\n\tErrMappingDestinationNotSupportedForImport = fmt.Errorf(\"%w: the only mapping function allowed for import transforms is {{Wildcard()}}\", ErrInvalidMappingDestination)\n)\n\n// mappingDestinationErr is a type of subject mapping destination error\ntype mappingDestinationErr struct {\n\ttoken string\n\terr   error\n}\n\nfunc (e *mappingDestinationErr) Error() string {\n\tif e.token == _EMPTY_ {\n\t\treturn e.err.Error()\n\t}\n\treturn fmt.Sprintf(\"%s in %s\", e.err, e.token)\n}\n","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L229-L265","documentation":"This error wraps ErrInvalidMappingDestination and is thrown when a mapping destination function is passed more arguments than allowed. transformIndexIntArgsHelper rejects more than 2 args, and a Wildcard destination token with any argument beyond the single allowed form is rejected in indexPlaceHolders.","triggerScenarios":"Calling NewSubjectTransformWithStrict with '{{Split(1, 2, 3)}}' (3 args) or a wildcard destination token carrying extra parenthesized arguments.","commonSituations":"Misunderstanding of the mapping function grammar when writing stream import mappings; accidentally leaving placeholder arguments from a copied example.","solutions":["Reduce the function to at most 2 arguments, e.g. '{{Split(index, value)}}'","Use '{{Wildcard()}}' with no extra arguments for plain wildcard mapping destinations","Validate the transform with NewSubjectTransformWithStrict before applying it"],"exampleFix":"// before\ndest := \"out.{{Split(1, 2, 3)}}\"\n// after\ndest := \"out.{{Split(1, 2)}}\"","handlingStrategy":"validation","validationCode":"func argCountOK(dest string) bool {\n    re := regexp.MustCompile(`\\{\\{\\w+\\((.*)\\)\\}}`)\n    for _, m := range re.FindAllStringSubmatch(dest, -1) {\n        inner := strings.TrimSpace(m[1])\n        if inner == \"\" {\n            continue\n        }\n        if n := len(strings.Split(inner, \",\")); n > 2 {\n            return false\n        }\n    }\n    return true\n}","typeGuard":"func isMappingDestinationErr(err error) bool {\n    var mde *mappingDestinationErr\n    return errors.As(err, &mde)\n}","tryCatchPattern":"_, err := NewSubjectTransformWithStrict(dest)\nif errors.Is(err, server.ErrMappingDestinationTooManyArgs) {\n    // trim function to at most 2 args\n}","preventionTips":["Limit destination functions to at most 2 arguments","Never add extra parameters to {{Wildcard()}}","Test every mapping string with NewSubjectTransformWithStrict before deployment"],"tags":["jetstream","subject-transform","config-validation"],"backgroundTag":"invalid-subject-mapping-destination","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}