{"record":{"id":"818b030afec96277","repo":"nats-io/nats-server","slug":"stream-republish-transform-from-s-to-s-w","errorCode":null,"errorMessage":"stream republish transform from '%s' to '%s': %w","messagePattern":"stream republish transform from '(.+?)' to '(.+?)': %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":1063,"sourceCode":"\t\tmset.ackq = newIPQueue[uint64](s, qpfx+\"acks\")\n\t}\n\n\t// Check for input subject transform\n\tif cfg.SubjectTransform != nil {\n\t\ttr, err := NewSubjectTransform(cfg.SubjectTransform.Source, cfg.SubjectTransform.Destination)\n\t\tif err != nil {\n\t\t\tjsa.mu.Unlock()\n\t\t\treturn nil, fmt.Errorf(\"stream subject transform from '%s' to '%s': %w\", cfg.SubjectTransform.Source, cfg.SubjectTransform.Destination, err)\n\t\t}\n\t\tmset.itr = tr\n\t}\n\n\t// Check for RePublish.\n\tif cfg.RePublish != nil {\n\t\ttr, err := NewSubjectTransform(cfg.RePublish.Source, cfg.RePublish.Destination)\n\t\tif err != nil {\n\t\t\tjsa.mu.Unlock()\n\t\t\treturn nil, fmt.Errorf(\"stream republish transform from '%s' to '%s': %w\", cfg.RePublish.Source, cfg.RePublish.Destination, err)\n\t\t}\n\t\t// Assign our transform for republishing.\n\t\tmset.tr = tr\n\t}\n\tstoreDir := filepath.Join(jsa.storeDir, streamsDir, cfg.Name)\n\tjsa.mu.Unlock()\n\n\t// Bind to the user account.\n\tc.registerWithAccount(a)\n\t// Bind to the system account.\n\tic.registerWithAccount(s.SystemAccount())\n\n\t// Create the appropriate storage\n\tfsCfg := fsConfig\n\tif fsCfg == nil {\n\t\tfsCfg = &FileStoreConfig{}\n\t\t// If we are file based and not explicitly configured\n\t\t// we may be able to auto-tune based on max msgs or bytes.","sourceCodeStart":1045,"sourceCodeEnd":1081,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1045-L1081","documentation":"This error wraps a failure from NewSubjectTransform when a stream's RePublish configuration contains a subject transform that cannot be built. The server rejects stream creation/update rather than starting a stream whose republishing would silently drop or misroute messages. The wrapped error identifies the specific problem with the Source or Destination subject.","triggerScenarios":"Calling StreamConfig.AddStream (or updating) with cfg.RePublish set to a RePublish{Source, Destination} whose Source is an invalid subject (wildcards misplaced, tokens >1 char) or whose Destination is not a valid transform target (e.g. contains wildcard tokens the Source does not provide).","commonSituations":"Typos in republish subjects; using '*' or '>' in the Destination that the Source doesn't supply; copy-pasting subjects with spaces; constructing subjects dynamically from user input; NATS server version differences in transform validation rules.","solutions":["Fix the RePublish.Source subject so it is a valid NATS subject (no spaces, wildcard rules respected).","Ensure RePublish.Destination wildcard tokens only reference tokens present in the Source (e.g. Source 'foo.*.bar' -> Destination 'baz.*' not 'baz.>').","Print the wrapped %w error to see the exact subject-transform failure from NewSubjectTransform.","Test subject strings with a validator before assigning them to cfg.RePublish."],"exampleFix":"// before\ncfg := jetstream.StreamConfig{\n  Name: \"ORDERS\",\n  RePublish: &jetstream.RePublish{Source: \"orders..\", Destination: \"rep.>\"},\n}\n// after\ncfg := jetstream.StreamConfig{\n  Name: \"ORDERS\",\n  RePublish: &jetstream.RePublish{Source: \"orders.*\", Destination: \"rep.orders\"},\n}","handlingStrategy":"validation","validationCode":"func validRepublish(rp *jetstream.RePublish) error {\n  if rp == nil { return nil }\n  for _, s := range []string{rp.Source, rp.Destination} {\n    if s == \"\" || strings.ContainsAny(s, \" \\t\") { return fmt.Errorf(\"invalid subject %q\", s) }\n  }\n  srcTok := strings.Split(rp.Source, \".\")\n  for i, t := range strings.Split(rp.Destination, \".\") {\n    if (t == \"*\" || t == \">\") && (i >= len(srcTok) || (srcTok[i] != \"*\" && srcTok[i] != \">\")) {\n      return fmt.Errorf(\"destination wildcard at %d has no source counterpart\", i)\n    }\n  }\n  return nil\n}","typeGuard":"func hasRepublish(cfg jetstream.StreamConfig) bool { return cfg.RePublish != nil }","tryCatchPattern":null,"preventionTips":["Validate republish subjects before every AddStream/UpdateStream call.","Never build subjects from raw user input without validation.","Keep destination wildcards aligned with source wildcard positions.","Log the wrapped error (%w) to see NewSubjectTransform's exact failure.","Pin and test subject transforms against your server version."],"tags":["jetstream","stream-config","subject-transform","validation"],"backgroundTag":"invalid-subject-transform","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}