{"record":{"id":"a3d103aabe7ffe0a","repo":"nats-io/nats-server","slug":"got-corrupted-escaped-character","errorCode":null,"errorMessage":"got corrupted escaped character","messagePattern":"got corrupted escaped character","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/ldap/dn.go","lineNumber":157,"sourceCode":"\t\tbuffer.Reset()\n\t\tunescapedTrailingSpaces = 0\n\t\treturn s\n\t}\n\n\tfor i := 0; i < len(str); i++ {\n\t\tchar := str[i]\n\t\tswitch {\n\t\tcase escaping:\n\t\t\tunescapedTrailingSpaces = 0\n\t\t\tescaping = false\n\t\t\tswitch char {\n\t\t\tcase ' ', '\"', '#', '+', ',', ';', '<', '=', '>', '\\\\':\n\t\t\t\tbuffer.WriteByte(char)\n\t\t\t\tcontinue\n\t\t\t}\n\t\t\t// Not a special character, assume hex encoded octet\n\t\t\tif len(str) == i+1 {\n\t\t\t\treturn nil, errors.New(\"got corrupted escaped character\")\n\t\t\t}\n\n\t\t\tdst := []byte{0}\n\t\t\tn, err := enchex.Decode([]byte(dst), []byte(str[i:i+2]))\n\t\t\tif err != nil {\n\t\t\t\treturn nil, fmt.Errorf(\"failed to decode escaped character: %s\", err)\n\t\t\t} else if n != 1 {\n\t\t\t\treturn nil, fmt.Errorf(\"expected 1 byte when un-escaping, got %d\", n)\n\t\t\t}\n\t\t\tbuffer.WriteByte(dst[0])\n\t\t\ti++\n\t\tcase char == '\\\\':\n\t\t\tunescapedTrailingSpaces = 0\n\t\t\tescaping = true\n\t\tcase char == '=':\n\t\t\tattribute.Type = stringFromBuffer()\n\t\t\t// Special case: If the first character in the value is # the following data\n\t\t\t// is BER encoded. Throw an error since not supported right now.","sourceCodeStart":139,"sourceCodeEnd":175,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/internal/ldap/dn.go#L139-L175","documentation":"Returned by memStore.AddConsumer when creating a consumer in the in-memory stream store with a nil config or an empty consumer name. The memStore refuses to register a consumer it cannot identify or configure, since cfg is dereferenced (copied) right after the check. This is a programming/argument error, not a runtime state issue.","triggerScenarios":"Calling memStore.AddConsumer(nil, \"myconsumer\") or memStore.AddConsumer(&ConsumerConfig{}, \"\") — i.e. nil cfg, or name == empty string.","commonSituations":"JetStream consumer creation where a template/default ConsumerConfig failed to load (nil pointer passed through), or code paths constructing consumers from API requests that omitted the durable/stream name field.","solutions":["Ensure the *ConsumerConfig passed to AddConsumer is non-nil; construct a default config if needed","Ensure the consumer name argument is a non-empty string before calling AddConsumer","Trace upstream where the config was lost (e.g. JSON decode of consumer create request) and reject it earlier with a proper API error"],"exampleFix":"// before\no, err := ms.AddConsumer(nil, name)\n// after\nif cfg == nil {\n    cfg = &ConsumerConfig{}\n}\nif name == \"\" {\n    return errors.New(\"consumer name required\")\n}\no, err := ms.AddConsumer(cfg, name)","handlingStrategy":"validation","validationCode":"if cfg == nil || name == \"\" {\n    return fmt.Errorf(\"consumer requires config and name\")\n}\no, err := ms.AddConsumer(cfg, name)","typeGuard":"func hasConsumerConfig(cfg *ConsumerConfig, name string) bool {\n    return cfg != nil && name != \"\"\n}","tryCatchPattern":"o, err := ms.AddConsumer(cfg, name)\nif err != nil && strings.Contains(err.Error(), \"bad consumer config\") {\n    // fix inputs: build default config, ensure non-empty name\n}","preventionTips":["Always construct a ConsumerConfig via defaults/merge before AddConsumer","Reject empty consumer names at the API boundary","Add unit tests covering nil-config and empty-name inputs"],"tags":["jetstream","validation","consumer-config"],"backgroundTag":"invalid-consumer-config","analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}