{"record":{"id":"7bac80356f456919","repo":"nats-io/nats-server","slug":"invalid-mapping-destination-not-enough-arguments","errorCode":null,"errorMessage":"invalid mapping destination: not enough arguments passed to the function","messagePattern":"invalid mapping destination: not enough arguments passed to the function","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":241,"sourceCode":"\tErrLeafNodeMinVersionRejected = errors.New(\"connection rejected since minimum version required is\")\n\n\t// ErrInvalidMappingDestination is used for all subject mapping destination errors\n\tErrInvalidMappingDestination = errors.New(\"invalid mapping destination\")\n\n\t// ErrInvalidMappingDestinationSubject is used to error on a bad transform destination mapping\n\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 {","sourceCodeStart":223,"sourceCodeEnd":259,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L223-L259","documentation":"This error wraps ErrInvalidMappingDestination and indicates a mapping destination function was invoked without the required number of arguments. indexPlaceHolders/transformIndexIntArgsHelper require exactly 2 arguments (a wildcard index and an integer value) for integer-taking functions like Split/Join, and Wildcard() with a single empty-argument form is also rejected.","triggerScenarios":"Calling NewSubjectTransformWithStrict (via transformIndexIntArgsHelper) with fewer than 2 args to an int-args destination function, e.g. '{{Split()}}' or '{{Split(1)}}'; or indexPlaceHolders receiving a single empty-string argument.","commonSituations":"Typos in account import/export mapping config where function arguments were accidentally deleted; templating tools that strip empty arguments.","solutions":["Supply both required arguments, e.g. '{{Split(*, 2)}}' style with a wildcard index and an integer value","Remove the function entirely if a plain wildcard '{{Wildcard()}}' destination was intended","Validate the transform with NewSubjectTransformWithStrict in a test before applying the account config"],"exampleFix":"// before\ndest := \"out.{{Split()}}\"\n// after\ndest := \"out.{{Split(1, 0)}}\"","handlingStrategy":"validation","validationCode":"func hasEnoughArgs(dest string) bool {\n    re := regexp.MustCompile(`\\{\\{(Split|Join|Wildcard)\\((.*)\\)\\}}`)\n    for _, m := range re.FindAllStringSubmatch(dest, -1) {\n        args := strings.Split(m[2], \",\")\n        if m[1] != \"Wildcard\" && len(args) < 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.ErrMappingDestinationNotEnoughArgs) {\n    // supply both function args or use {{Wildcard()}}\n}","preventionTips":["Always pass exactly two arguments to int-args functions like Split/Join","Use bare {{Wildcard()}} for plain wildcard destinations","Lint account configs for empty function argument lists"],"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-08T15:18:49.778Z"}