{"record":{"id":"9e239a4322d6c001","repo":"hyperledger/fabric","slug":"invalid-label-s-label-must-be-non-empty-can-o","errorCode":null,"errorMessage":"invalid label '%s'. Label must be non-empty, can only consist of alphanumerics, symbols from '.+-_', and can only begin with alphanumerics","messagePattern":"invalid label '(.+?)'\\. Label must be non-empty, can only consist of alphanumerics, symbols from '\\.\\+-_', and can only begin with alphanumerics","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/chaincode/persistence/chaincode_package.go","lineNumber":253,"sourceCode":"// information (for instance the DB indexes) from a code package.\ntype MetadataProvider interface {\n\tGetDBArtifacts(codePackage []byte) ([]byte, error)\n}\n\n// ChaincodePackageParser provides the ability to parse chaincode packages.\ntype ChaincodePackageParser struct {\n\tMetadataProvider MetadataProvider\n}\n\n// LabelRegexp is the regular expression controlling the allowed characters\n// for the package label.\nvar LabelRegexp = regexp.MustCompile(`^[[:alnum:]][[:alnum:]_.+-]*$`)\n\n// ValidateLabel return an error if the provided label contains any invalid\n// characters, as determined by LabelRegexp.\nfunc ValidateLabel(label string) error {\n\tif !LabelRegexp.MatchString(label) {\n\t\treturn errors.Errorf(\"invalid label '%s'. Label must be non-empty, can only consist of alphanumerics, symbols from '.+-_', and can only begin with alphanumerics\", label)\n\t}\n\n\treturn nil\n}\n\n// Parse parses a set of bytes as a chaincode package\n// and returns the parsed package as a struct\nfunc (ccpp ChaincodePackageParser) Parse(source []byte) (*ChaincodePackage, error) {\n\tccPackageMetadata, codePackage, err := ParseChaincodePackage(source)\n\tif err != nil {\n\t\treturn nil, err\n\t}\n\n\tdbArtifacts, err := ccpp.MetadataProvider.GetDBArtifacts(codePackage)\n\tif err != nil {\n\t\treturn nil, errors.WithMessage(err, \"error retrieving DB artifacts from code package\")\n\t}\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/core/chaincode/persistence/chaincode_package.go#L235-L271","documentation":"ValidateLabel rejects labels that don't match LabelRegexp ^[[:alnum:]][[:alnum:]_.+-]*$: the label must be non-empty, start with an alphanumeric, and contain only alphanumerics and . + - _ characters. It is called by ParseChaincodePackage/Parse and by Validate when a package or install request carries an invalid label.","triggerScenarios":"Calling ValidateLabel directly, installing/installing-and-approving a package whose --label contains spaces, colons, slashes, uppercase-forbidden symbols, non-ASCII characters, or is empty.","commonSituations":"Labels auto-built from image tags containing ':' or '/' (e.g. myrepo/mycc:1.0), labels with spaces from shell variables, or empty labels when the flag was omitted in scripts.","solutions":["Change the label to start with a letter/digit and use only [A-Za-z0-9_.+-], e.g. mycc-v1.0.","Sanitize derived labels: replace ':' and '/' in image tags with '-' or '_' before packaging.","Quote shell variables and verify non-empty: label=\"${LABEL:?label required}\".","Pre-validate with persistence.ValidateLabel before packaging in Go code."],"exampleFix":"// before\nlabel=\"myrepo/mycc:1.0\"\n// after\nlabel=\"myrepo-mycc-1.0\"","handlingStrategy":"validation","validationCode":"var labelRe = regexp.MustCompile(`^[[:alnum:]][[:alnum:]_.+-]*$`)\nfunc labelValid(s string) bool { return labelRe.MatchString(s) }\nif !labelValid(label) {\n\treturn fmt.Errorf(\"label %q invalid; use only alphanumerics and .+-_ and start alphanumerically\", label)\n}","typeGuard":null,"tryCatchPattern":"if err := persistence.ValidateLabel(label); err != nil {\n\treturn fmt.Errorf(\"fix --label (no spaces/:/ or / allowed): %w\", err)\n}","preventionTips":["Derive labels by replacing ':' and '/' in image tags with '-'.","Quote and default-check shell variables used as labels.","Call persistence.ValidateLabel early in tooling before packaging.","Keep labels short, e.g. name-version like mycc-1.0."],"tags":["validation","label","chaincode-package"],"backgroundTag":"label-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"}