{"record":{"id":"ac284d0f3d15de95","repo":"hyperledger/fabric","slug":"channel-id-illegal-cannot-be-empty","errorCode":null,"errorMessage":"channel ID illegal, cannot be empty","messagePattern":"channel ID illegal, cannot be empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/configtx/validator.go","lineNumber":86,"sourceCode":"}\n\n// ValidateChannelID makes sure that proposed channel IDs comply with the\n// following restrictions:\n//  1. Contain only lower case ASCII alphanumerics, dots '.', and dashes '-'\n//  2. Are shorter than 250 characters.\n//  3. Start with a letter\n//\n// This is the intersection of the Kafka restrictions and CouchDB restrictions\n// with the following exception: '.' is converted to '_' in the CouchDB naming\n// This is to accommodate existing channel names with '.', especially in the\n// behave tests which rely on the dot notation for their sluggification.\n//\n// note: this function is a copy of the same in core/tx/endorser/parser.go\nfunc ValidateChannelID(channelID string) error {\n\tre, _ := regexp.Compile(ChannelAllowedChars)\n\t// Length\n\tif len(channelID) <= 0 {\n\t\treturn errors.Errorf(\"channel ID illegal, cannot be empty\")\n\t}\n\tif len(channelID) > MaxLength {\n\t\treturn errors.Errorf(\"channel ID illegal, cannot be longer than %d\", MaxLength)\n\t}\n\n\t// Illegal characters\n\tmatched := re.FindString(channelID)\n\tif len(matched) != len(channelID) {\n\t\treturn errors.Errorf(\"'%s' contains illegal characters\", channelID)\n\t}\n\n\treturn nil\n}\n\n// NewValidatorImpl constructs a new implementation of the Validator interface.\nfunc NewValidatorImpl(channelID string, config *cb.Config, namespace string, pm policies.Manager) (*ValidatorImpl, error) {\n\tif config == nil {\n\t\treturn nil, errors.Errorf(\"nil config parameter\")","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/configtx/validator.go#L68-L104","documentation":"ValidateChannelID ensures a proposed channel ID complies with Fabric naming rules; an empty string is rejected outright. Channel IDs must be non-empty, at most MaxLength (250) characters, and contain only allowed characters (lowercase alphanumerics, dots, dashes). It runs when creating a channel config and when extracting the channel ID from envelopes.","triggerScenarios":"Creating a channel with an empty name in configtxgen or channel creation tx; calling NewValidatorImpl or extractChannelID with an envelope lacking a channel header value.","commonSituations":"configtx.yaml profile with a missing/blank ChannelID; a script passing an unset variable as channel name; parsing a malformed envelope whose ChannelHeader has an empty ChannelId.","solutions":["Supply a non-empty ChannelID when generating/creating the channel (e.g. in configtxgen -channelID)","Check the profile's name/ChannelID fields in configtx.yaml","Verify the ChannelHeader.ChannelId is populated in any hand-built transaction envelope","Fix scripts so the channel name variable is not empty"],"exampleFix":"// before\n// configtx.yaml\n# Channel: # ChannelID missing\n// after\nChannel:\n  ChannelID: mychannel","handlingStrategy":"validation","validationCode":"if channelID == \"\" {\n    return errors.New(\"channel ID must not be empty\")\n}\nvar chanAllowed = regexp.MustCompile(`^[a-z0-9.-]+$`)\nif len(channelID) > 250 || !chanAllowed.MatchString(channelID) {\n    return errors.Errorf(\"invalid channel ID %q\", channelID)\n}","typeGuard":"func validChannelID(id string) bool {\n    if id == \"\" || len(id) > 250 {\n        return false\n    }\n    return strings.TrimLeft(id, \"abcdefghijklmnopqrstuvwxyz0123456789.-\") == \"\"\n}","tryCatchPattern":"if err := configtx.ValidateChannelID(chID); err != nil {\n    return fmt.Errorf(\"channel creation aborted: %w\", err)\n}","preventionTips":["Always set ChannelID in configtx.yaml profiles before running configtxgen","Validate channel names in scripts before invoking channel creation","Check ChannelHeader.ChannelId is populated when crafting envelopes","Call ValidateChannelID early in any channel-creation tooling"],"tags":["go","fabric","channel","validation","naming"],"backgroundTag":"channel-id-validation-failed","analyzedSha":"2736b63f8fd5932511d56fe68b7039d15977f7f6","analyzedAt":"2026-09-04T08:52:36.465Z","contentChangedAt":"2026-09-04T08:52:36.465Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}