{"record":{"id":"e65d0348a1b7e639","repo":"nats-io/nats-server","slug":"invalid-compression","errorCode":null,"errorMessage":"invalid compression","messagePattern":"invalid compression","errorType":"error_code","errorClass":"JSStreamInvalidConfigError","httpStatus":null,"severity":"error","filePath":"server/stream.go","lineNumber":1900,"sourceCode":"\n\tvar metadataLen int\n\tfor k, v := range config.Metadata {\n\t\tmetadataLen += len(k) + len(v)\n\t}\n\tif metadataLen > JSMaxMetadataLen {\n\t\treturn StreamConfig{}, NewJSStreamInvalidConfigError(fmt.Errorf(\"stream metadata exceeds maximum size of %d bytes\", JSMaxMetadataLen))\n\t}\n\n\tcfg := *config\n\n\tif _, err := cfg.Retention.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid retention\"))\n\t}\n\tif _, err := cfg.Discard.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid discard policy\"))\n\t}\n\tif _, err := cfg.Compression.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid compression\"))\n\t}\n\n\t// Make file the default.\n\tif cfg.Storage == 0 {\n\t\tcfg.Storage = FileStorage\n\t}\n\tif _, err := cfg.Storage.MarshalJSON(); err != nil {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"invalid storage type\"))\n\t}\n\n\tif cfg.Replicas == 0 {\n\t\tcfg.Replicas = 1\n\t}\n\tif cfg.Replicas > StreamMaxReplicas {\n\t\treturn cfg, NewJSStreamInvalidConfigError(fmt.Errorf(\"maximum replicas is %d\", StreamMaxReplicas))\n\t}\n\tif cfg.Replicas < 0 {\n\t\treturn cfg, NewJSReplicasCountCannotBeNegativeError()","sourceCodeStart":1882,"sourceCodeEnd":1918,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/stream.go#L1882-L1918","documentation":"cfg.Compression (Compression enum: None or S2) failed to marshal to JSON, meaning it is not a recognized compression algorithm value. The server rejects the config with 'invalid compression'. Compression support also requires a sufficiently new server (2.10+).","triggerScenarios":"Passing an out-of-range Compression value (e.g. Compression(9)); a zero-value struct field where 0 is not a valid enum member; sending an older client's compression value to a server or vice versa.","commonSituations":"Upgrading clients across NATS versions where compression constants changed; enabling S2 compression against an older server that doesn't know the field; hand-rolled config structs with wrong numeric values.","solutions":["Set Compression to jetstream.NoCompression or jetstream.S2Compression explicitly.","Omit the field if you don't need compression.","Confirm the server is >=2.10 before enabling S2 compression.","Validate the enum value numerically before building the config."],"exampleFix":"// before\ncfg := jetstream.StreamConfig{Name: \"ORDERS\", Compression: jetstream.Compression(9)}\n// after\ncfg := jetstream.StreamConfig{Name: \"ORDERS\", Compression: jetstream.S2Compression}","handlingStrategy":"validation","validationCode":"func validCompression(c jetstream.Compression) error {\n  switch c {\n  case jetstream.NoCompression, jetstream.S2Compression:\n    return nil\n  }\n  return fmt.Errorf(\"invalid compression: %d\", int(c))\n}","typeGuard":"func isKnownCompression(c jetstream.Compression) bool {\n  return c == jetstream.NoCompression || c == jetstream.S2Compression\n}","tryCatchPattern":null,"preventionTips":["Set Compression only from named constants (NoCompression/S2Compression).","Verify server >= 2.10 before enabling S2 compression.","Omit the field if compression is not required.","Upgrade client and server together to avoid enum skew."],"tags":["jetstream","stream-config","compression","enum"],"backgroundTag":"invalid-compression","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}