{"record":{"id":"326994dded5c7e1a","repo":"hyperledger/fabric","slug":"invalid-number-of-args-expected-only-the-output-f","errorCode":null,"errorMessage":"invalid number of args. expected only the output file","messagePattern":"invalid number of args\\. expected only the output file","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/lifecycle/chaincode/package.go","lineNumber":111,"sourceCode":"\t\t\"path\",\n\t\t\"peerAddresses\",\n\t\t\"tlsRootCertFiles\",\n\t\t\"connectionProfile\",\n\t}\n\tattachFlags(chaincodePackageCmd, flagList)\n\n\treturn chaincodePackageCmd\n}\n\n// PackageChaincode packages a chaincode.\nfunc (p *Packager) PackageChaincode(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 output file\")\n\t}\n\tp.setInput(args[0])\n\n\treturn p.Package()\n}\n\nfunc (p *Packager) setInput(outputFile string) {\n\tp.Input = &PackageInput{\n\t\tOutputFile: outputFile,\n\t\tPath:       chaincodePath,\n\t\tType:       chaincodeLang,\n\t\tLabel:      packageLabel,\n\t}\n}\n\n// Package packages chaincodes into the package type,\n// (.tar.gz) used by _lifecycle and writes it to disk\nfunc (p *Packager) Package() error {","sourceCodeStart":93,"sourceCodeEnd":129,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/lifecycle/chaincode/package.go#L93-L129","documentation":"PackageChaincode enforces cobra-style positional argument validation: the package subcommand accepts exactly one positional argument, the output package file. Any extra or missing argument causes this error and usage is silenced so only the message is shown.","triggerScenarios":"`peer lifecycle chaincode package` called with 0 args, 2+ positional args (e.g. forgetting a --flag and having its value counted positionally: `package out.tar.gz golang --path ...` treats 'golang' as a second positional arg), or quoting mistakes splitting paths into multiple args.","commonSituations":"Dropped/misspelled flags (--lan instead of --lang) making extra positionals; spaces in unquoted output paths; scripts appending extra arguments.","solutions":["Use exactly: peer lifecycle chaincode package <output-file> --path <path> --lang <lang> --label <label>.","Quote paths containing spaces: package \"/tmp/my packages/basic.tar.gz\" ...","Check each flag spelling; an unaccepted flag's value becomes a stray positional argument.","Print the actual command in scripts (set -x) to count positional args."],"exampleFix":"// before (missing --lang flag, so 'golang' becomes a stray positional)\npeer lifecycle chaincode package basic.tar.gz golang --path . --label basic_1.0\n// after\npeer lifecycle chaincode package basic.tar.gz --path . --lang golang --label basic_1.0","handlingStrategy":"validation","validationCode":"#!/bin/bash\n# Count positional args the way cobra will see them\nargs=(\"\")\n: \"${1:?usage: package.sh <output.tar.gz>}\"\npeer lifecycle chaincode package \"$1\" \\\n  --path \"$CC_SRC_PATH\" \\\n  --lang \"$CC_LANG\" \\\n  --label \"$LABEL\"\n# Exactly one positional argument: \"$1\"","typeGuard":null,"tryCatchPattern":"if ! out=$(peer lifecycle chaincode package \"$@\" 2>&1); then\n  case \"$out\" in\n    *\"invalid number of args\"*) echo \"Check flag spelling/quoting; package takes only the output file positionally\"; exit 2 ;;\n    *) echo \"$out\"; exit 1 ;;\n  esac\nfi","preventionTips":["Double-check flag spellings (--lang, not --lan) so values don't leak into positionals.","Quote any path containing spaces.","Run scripts with set -x once to verify the final command line.","Keep the package invocation in one tested wrapper script."],"tags":["hyperledger-fabric","cli","argument-validation","cobra"],"backgroundTag":"invalid-argument-count","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"}