nats-io/nats-server · error

invalid mapping destination: not enough arguments passed to

Error message

invalid mapping destination: not enough arguments passed to the function

What it means

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.

Source

Thrown at server/errors.go:241

	ErrLeafNodeMinVersionRejected = errors.New("connection rejected since minimum version required is")

	// ErrInvalidMappingDestination is used for all subject mapping destination errors
	ErrInvalidMappingDestination = errors.New("invalid mapping destination")

	// ErrInvalidMappingDestinationSubject is used to error on a bad transform destination mapping
	ErrInvalidMappingDestinationSubject = fmt.Errorf("%w: invalid transform", ErrInvalidMappingDestination)

	// ErrMappingDestinationNotUsingAllWildcards is used to error on a transform destination not using all of the token wildcards
	ErrMappingDestinationNotUsingAllWildcards = fmt.Errorf("%w: not using all of the token wildcard(s)", ErrInvalidMappingDestination)

	// ErrUnknownMappingDestinationFunction is returned when a subject mapping destination contains an unknown mustache-escaped mapping function.
	ErrUnknownMappingDestinationFunction = fmt.Errorf("%w: unknown function", ErrInvalidMappingDestination)

	// ErrMappingDestinationIndexOutOfRange is returned when the mapping destination function is passed an out of range wildcard index value for one of it's arguments
	ErrMappingDestinationIndexOutOfRange = fmt.Errorf("%w: wildcard index out of range", ErrInvalidMappingDestination)

	// ErrMappingDestinationNotEnoughArgs is returned when the mapping destination function is not passed enough arguments
	ErrMappingDestinationNotEnoughArgs = fmt.Errorf("%w: not enough arguments passed to the function", ErrInvalidMappingDestination)

	// ErrMappingDestinationInvalidArg is returned when the mapping destination function is passed and invalid argument
	ErrMappingDestinationInvalidArg = fmt.Errorf("%w: function argument is invalid or in the wrong format", ErrInvalidMappingDestination)

	// ErrMappingDestinationTooManyArgs is returned when the mapping destination function is passed too many arguments
	ErrMappingDestinationTooManyArgs = fmt.Errorf("%w: too many arguments passed to the function", ErrInvalidMappingDestination)

	// 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)
	ErrMappingDestinationNotSupportedForImport = fmt.Errorf("%w: the only mapping function allowed for import transforms is {{Wildcard()}}", ErrInvalidMappingDestination)
)

// mappingDestinationErr is a type of subject mapping destination error
type mappingDestinationErr struct {
	token string
	err   error
}

func (e *mappingDestinationErr) Error() string {

View on GitHub (pinned to 3a66a489d2)

Solutions

  1. Supply both required arguments, e.g. '{{Split(*, 2)}}' style with a wildcard index and an integer value
  2. Remove the function entirely if a plain wildcard '{{Wildcard()}}' destination was intended
  3. Validate the transform with NewSubjectTransformWithStrict in a test before applying the account config

Example fix

// before
dest := "out.{{Split()}}"
// after
dest := "out.{{Split(1, 0)}}"
Defensive patterns

Strategy: validation

Validate before calling

func hasEnoughArgs(dest string) bool {
    re := regexp.MustCompile(`\{\{(Split|Join|Wildcard)\((.*)\)\}}`)
    for _, m := range re.FindAllStringSubmatch(dest, -1) {
        args := strings.Split(m[2], ",")
        if m[1] != "Wildcard" && len(args) < 2 {
            return false
        }
    }
    return true
}

Type guard

func isMappingDestinationErr(err error) bool {
    var mde *mappingDestinationErr
    return errors.As(err, &mde)
}

Try / catch

_, err := NewSubjectTransformWithStrict(dest)
if errors.Is(err, server.ErrMappingDestinationNotEnoughArgs) {
    // supply both function args or use {{Wildcard()}}
}

Prevention

When it happens

Trigger: 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.

Common situations: Typos in account import/export mapping config where function arguments were accidentally deleted; templating tools that strip empty arguments.

Related errors


AI-assisted analysis of nats-io/nats-server@3a66a489d2 (2026-09-02). Data as JSON: /api/errors/7bac80356f456919. Report an issue: GitHub.