{"record":{"id":"b33b132bc7069d0a","repo":"gofr-dev/gofr","slug":"create-or-update-stream-error","errorCode":null,"errorMessage":"create or update stream error","messagePattern":"create or update stream error","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/datasource/pubsub/nats/errors.go","lineNumber":19,"sourceCode":"package nats\n\nimport \"errors\"\n\nvar (\n\t// Client Errors.\n\terrServerNotProvided       = errors.New(\"client server address not provided\")\n\terrSubjectsNotProvided     = errors.New(\"subjects not provided\")\n\terrConsumerNotProvided     = errors.New(\"consumer name not provided\")\n\terrConsumerCreationError   = errors.New(\"consumer creation error\")\n\terrFailedToDeleteStream    = errors.New(\"failed to delete stream\")\n\terrPublishError            = errors.New(\"publish error\")\n\terrJetStreamNotConfigured  = errors.New(\"jStream is not configured\")\n\terrJetStreamCreationFailed = errors.New(\"jStream creation failed\")\n\terrJetStream               = errors.New(\"jStream error\")\n\terrCreateStream            = errors.New(\"create stream error\")\n\terrDeleteStream            = errors.New(\"delete stream error\")\n\terrGetStream               = errors.New(\"get stream error\")\n\terrCreateOrUpdateStream    = errors.New(\"create or update stream error\")\n\terrHandlerError            = errors.New(\"handler error\")\n\terrConnectionError         = errors.New(\"connection error\")\n\terrSubscriptionError       = errors.New(\"subscription error\")\n)\n","sourceCodeStart":1,"sourceCodeEnd":24,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/datasource/pubsub/nats/errors.go#L1-L24","documentation":"errCreateOrUpdateStream (errors.go:19) is returned by StreamManager.CreateOrUpdateStream when the jetstream CreateOrUpdateStream API fails — neither creating nor updating the stream succeeded. Exercised by TestStreamManager_CreateOrUpdateStream_Error.","triggerScenarios":"Calling CreateOrUpdateStream with a StreamConfig that conflicts with an existing stream's immutable fields, invalid subjects, resource limits, or no JetStream connection.","commonSituations":"Changing retention or storage on an existing stream via upsert; replicas requested above account limits; multiple deploy pipelines racing to define the same stream differently.","solutions":["Inspect the wrapped NATS error — upsert failures usually name the conflicting field (retention/storage/discard policy).","Match the existing stream's configuration (`nats stream info`) or delete and recreate the stream if reconfiguration is required.","Validate subject patterns and reduce Replicas to what the account/cluster allows.","Ensure only one provisioning path owns the stream config to avoid deployment races."],"exampleFix":"// before: changing retention on an existing stream via upsert fails\nerr := sm.CreateOrUpdateStream(ctx, &jetstream.StreamConfig{Name: \"ORDERS\", Retention: jetstream.LimitsPolicy})\n// after: match existing config or recreate\ncfg, _ := js.Stream(ctx, \"ORDERS\")\n_ = cfg // inspect existing settings; keep them consistent in StreamConfig","handlingStrategy":"validation","validationCode":"existing, err := js.Stream(ctx, cfg.Name)\nif err == nil {\n    if existing.CachedInfo().Config.Retention != cfg.Retention {\n        return fmt.Errorf(\"stream %q exists with different retention; manual migration required\", cfg.Name)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := sm.CreateOrUpdateStream(ctx, cfg); err != nil {\n    return fmt.Errorf(\"upsert stream %s failed: %w (check conflicting config with `nats stream info %s`)\", cfg.Name, err, cfg.Name)\n}","preventionTips":["Fetch the existing stream config and diff it before upserting.","Never change immutable fields (storage, retention) via upsert; plan a migration.","Keep replicas within account/cluster limits.","Use a single owner for stream definitions to avoid deploy races."],"tags":["nats","jetstream","stream","gofr"],"backgroundTag":"stream-update-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}