{"record":{"id":"84cfd985c1581e06","repo":"nats-io/nats-server","slug":"invalid-mapping-destination-function-argument-is","errorCode":null,"errorMessage":"invalid mapping destination: function argument is invalid or in the wrong format","messagePattern":"invalid mapping destination: function argument is invalid or in the wrong format","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":244,"sourceCode":"\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 {\n\tif e.token == _EMPTY_ {\n\t\treturn e.err.Error()\n\t}","sourceCodeStart":226,"sourceCodeEnd":262,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L226-L262","documentation":"This error wraps ErrInvalidMappingDestination and is thrown when an argument to a mapping destination function cannot be parsed as the expected integer type. transformIndexIntArgsHelper uses strconv.Atoi on args[0] (wildcard index) and strconv.ParseInt on args[1] (32-bit int value); a non-numeric argument fails parsing and produces this error.","triggerScenarios":"Calling NewSubjectTransformWithStrict with a destination function whose arguments are non-numeric or malformed, e.g. '{{Split(a, b)}}' or arguments containing characters that fail strconv parsing after space trimming.","commonSituations":"Typos like '{{Split(*, o)}}' (letter o instead of zero) in account mapping config; quoting or whitespace artifacts introduced by YAML/JSON config generation tools.","solutions":["Ensure args[0] is a plain decimal integer (the wildcard index) and args[1] is a decimal integer that fits in 32 bits","Remove stray quotes, units, or letters from the function arguments","Check the generated account config JSON/YAML for escaping issues around the destination string"],"exampleFix":"// before\ndest := \"out.{{Split(one, 2)}}\"\n// after\ndest := \"out.{{Split(1, 2)}}\"","handlingStrategy":"validation","validationCode":"func argsAreInts(dest string) bool {\n    re := regexp.MustCompile(`\\{\\{(?:Split|Join)\\(([^,]*),([^)]*)\\)\\}}`)\n    for _, m := range re.FindAllStringSubmatch(dest, -1) {\n        if _, err := strconv.Atoi(strings.TrimSpace(m[1])); err != nil {\n            return false\n        }\n        if _, err := strconv.ParseInt(strings.TrimSpace(m[2]), 10, 32); err != nil {\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.ErrMappingDestinationInvalidArg) {\n    // args must be decimal integers\n}","preventionTips":["Write function arguments as plain decimal integers, no quotes or units","Beware lookalike characters (letter O vs zero) in hand-written configs","Regenerate configs programmatically rather than hand-editing strings"],"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"}