{"record":{"id":"bb8ab84edb355d6c","repo":"hyperledger/fabric","slug":"invalid-number-of-args-expected-only-the-packaged","errorCode":null,"errorMessage":"invalid number of args. expected only the packaged chaincode file","messagePattern":"invalid number of args\\. expected only the packaged chaincode file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/calculatepackageid.go","lineNumber":90,"sourceCode":"\t\t\"peerAddresses\",\n\t\t\"tlsRootCertFiles\",\n\t\t\"connectionProfile\",\n\t\t\"output\",\n\t}\n\tattachFlags(calculatePackageIDCmd, flagList)\n\n\treturn calculatePackageIDCmd\n}\n\n// CalculatePackageID calculates the package ID for a packaged chaincode.\nfunc (p *PackageIDCalculator) CalculatePackageID(args []string) error {\n\tif p.Command != nil {\n\t\t// Parsing of the command line is done so silence cmd usage\n\t\tp.Command.SilenceUsage = true\n\t}\n\n\tif len(args) != 1 {\n\t\treturn errors.New(\"invalid number of args. expected only the packaged chaincode file\")\n\t}\n\tp.setInput(args[0])\n\n\treturn p.PackageID()\n}\n\n// PackageID calculates the package ID for a packaged chaincode and print it.\nfunc (p *PackageIDCalculator) PackageID() error {\n\terr := p.Input.Validate()\n\tif err != nil {\n\t\treturn err\n\t}\n\tpkgBytes, err := p.Reader.ReadFile(p.Input.PackageFile)\n\tif err != nil {\n\t\treturn errors.WithMessagef(err, \"failed to read chaincode package at '%s'\", p.Input.PackageFile)\n\t}\n\n\tmetadata, _, err := persistence.ParseChaincodePackage(pkgBytes)","sourceCodeStart":72,"sourceCodeEnd":108,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/calculatepackageid.go#L72-L108","documentation":"The calculatepackageid cobra command takes exactly one positional argument — the packaged chaincode file. CalculatePackageID rejects any other argument count with this error, before attempting to parse or hash the package. It guards against users passing flags-as-args or multiple files.","triggerScenarios":"Running `peer lifecycle chaincode calculatepackageid` with zero positional args, with more than one path, or relying on an older flag-based usage (-p/--package-file) that no longer maps to the positional arg (the flag may only set defaults).","commonSituations":"Scripts written against an older fabric-cli syntax where the package file was passed via a flag; accidental extra filenames (e.g. both a .tgz and a .tar.gz) glob-expanded onto the command line.","solutions":["Pass exactly one argument: `peer lifecycle chaincode calculatepackageid ./mycc_1.0.tgz`.","Quote or brace-expand globs so only the intended single .tgz file is passed.","If a wrapper script still uses a flag, update it to pass the package file as the single positional argument."],"exampleFix":"// before: flag-style or multiple args\npeer lifecycle chaincode calculatepackageid --package-file a.tgz b.tgz\n// after: exactly one positional arg\npeer lifecycle chaincode calculatepackageid ./mycc_1.0.tgz","handlingStrategy":"validation","validationCode":"args := []string{\"./mycc_1.0.tgz\"}\nif len(args) != 1 {\n    return errors.New(\"calculatepackageid takes exactly one positional arg: the packaged chaincode file\")\n}\nif _, err := os.Stat(args[0]); err != nil {\n    return fmt.Errorf(\"package file missing: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := cmd.CalculatePackageID(args); err != nil && strings.Contains(err.Error(), \"invalid number of args\") {\n    cmd.Usage()\n    return nil // show usage instead of a raw error\n}","preventionTips":["Quote globs in shell scripts so exactly one file is expanded.","Migrate any legacy flag-based invocations (--package-file) to the positional-argument syntax.","Wrap the command to assert argument count before exec."],"tags":["fabric","cli-argument-validation","usage-error"],"backgroundTag":"invalid-cli-argument","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"}