{"record":{"id":"c6f736febbfb4a8d","repo":"nats-io/nats-server","slug":"invalid-mapping-destination-not-using-all-of-the","errorCode":null,"errorMessage":"invalid mapping destination: not using all of the token wildcard(s)","messagePattern":"invalid mapping destination: not using all of the token wildcard\\(s\\)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/errors.go","lineNumber":232,"sourceCode":"\n\t// ErrDuplicateServerName is returned when processing a server remote connection and\n\t// the server reports that this server name is already used in the cluster.\n\tErrDuplicateServerName = errors.New(\"duplicate server name\")\n\n\t// ErrMinimumVersionRequired is returned when a connection is not at the minimum version required.\n\tErrMinimumVersionRequired = errors.New(\"minimum version required\")\n\t// ErrLeafNodeMinVersionRejected is the leafnode protocol error prefix used\n\t// when rejecting a remote due to leafnodes.min_version.\n\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)","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/errors.go#L214-L250","documentation":"ErrMappingDestinationNotUsingAllWildcards is returned by NewSubjectTransformWithStrict when the destination subject has fewer placeholders than the source subject has wildcards. In strict mode every source wildcard token must be consumed by the destination; otherwise the mapping would silently drop information, so the server rejects it.","triggerScenarios":"NewSubjectTransformWithStrict(source, dest) where the source contains N wildcards but the destination references fewer than N wildcard placeholders (strict mode on). Example: source 'foo.*.*' with destination 'bar.*'.","commonSituations":"Config `mappings` entries where the destination was hand-written and forgot to reuse a '*' from the source; tightening an existing mapping to strict validation after a server upgrade; JetStream subject transforms that drop wildcard tokens.","solutions":["Reference every source wildcard in the destination, in order, via '*' placeholders or transform functions like {{Wildcard(1)}}","If dropping wildcards is intentional, use the non-strict transform constructor (NewSubjectTransform) where allowed","Re-run the transform validation locally on all mapping entries after config changes"],"exampleFix":"// before\nsrc := \"foo.*.*\"\ndest := \"bar.*\" // drops the second wildcard\n// after\ndest := \"bar.*.*\" // or \"bar.{{Wildcard(1)}}.{{Wildcard(2)}}\"","handlingStrategy":"validation","validationCode":"srcWildcards := strings.Count(src, \"*\")\ndestPlaceholders := countWildcardsOrFuncs(dest)\nif destPlaceholders < srcWildcards {\n    return fmt.Errorf(\"dest %q must use all %d wildcards from %q\", dest, srcWildcards, src)\n}","typeGuard":"func usesAllWildcards(src, dest string) bool {\n    t, err := server.NewSubjectTransformWithStrict(src, dest)\n    return err == nil && t != nil\n}","tryCatchPattern":"if err != nil {\n    if errors.Is(err, server.ErrMappingDestinationNotUsingAllWildcards) {\n        return fmt.Errorf(\"mapping drops wildcards: %w\", err)\n    }\n}","preventionTips":["Mirror every '*' in the source into the destination","Count wildcards when generating destinations programmatically","Prefer explicit {{Wildcard(n)}} functions for clarity"],"tags":["subject-mapping","transform","wildcards"],"backgroundTag":"invalid-mapping-destination","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}