{"record":{"id":"9219db2487c7d202","repo":"hyperledger/fabric","slug":"could-not-read-file-s","errorCode":null,"errorMessage":"could not read file '%s'","messagePattern":"could not read file '(.+?)'","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/peer/chaincode/common.go","lineNumber":170,"sourceCode":"\ntype collectionConfigJson struct {\n\tName              string             `json:\"name\"`\n\tPolicy            string             `json:\"policy\"`\n\tRequiredPeerCount *int32             `json:\"requiredPeerCount\"`\n\tMaxPeerCount      *int32             `json:\"maxPeerCount\"`\n\tBlockToLive       uint64             `json:\"blockToLive\"`\n\tMemberOnlyRead    bool               `json:\"memberOnlyRead\"`\n\tMemberOnlyWrite   bool               `json:\"memberOnlyWrite\"`\n\tEndorsementPolicy *endorsementPolicy `json:\"endorsementPolicy,omitempty\"`\n}\n\n// GetCollectionConfigFromFile retrieves the collection configuration\n// from the supplied file; the supplied file must contain a\n// json-formatted array of collectionConfigJson elements\nfunc GetCollectionConfigFromFile(ccFile string) (*pb.CollectionConfigPackage, []byte, error) {\n\tfileBytes, err := os.ReadFile(ccFile)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrapf(err, \"could not read file '%s'\", ccFile)\n\t}\n\n\treturn getCollectionConfigFromBytes(fileBytes)\n}\n\n// getCollectionConfigFromBytes retrieves the collection configuration\n// from the supplied byte array; the byte array must contain a\n// json-formatted array of collectionConfigJson elements\nfunc getCollectionConfigFromBytes(cconfBytes []byte) (*pb.CollectionConfigPackage, []byte, error) {\n\tcconf := &[]collectionConfigJson{}\n\terr := json.Unmarshal(cconfBytes, cconf)\n\tif err != nil {\n\t\treturn nil, nil, errors.Wrap(err, \"could not parse the collection configuration\")\n\t}\n\n\tccarray := make([]*pb.CollectionConfig, 0, len(*cconf))\n\tfor _, cconfitem := range *cconf {\n\t\tp, err := policydsl.FromString(cconfitem.Policy)","sourceCodeStart":152,"sourceCodeEnd":188,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/internal/peer/chaincode/common.go#L152-L188","documentation":"GetCollectionConfigFromFile reads the private data collection configuration JSON from disk with os.ReadFile and wraps any read failure as \"could not read file '%s'\". The file must contain a JSON array of collectionConfigJson elements.","triggerScenarios":"peer chaincode approveformyorg/commit invoked with --collections-config pointing to a nonexistent, unreadable, or path-mistyped file.","commonSituations":"Wrong path/typo, file not mounted into a container where the peer CLI runs, permission errors, running CLI from a different working directory than expected.","solutions":["Verify the file path exists and is readable (ls -l / cat the file)","Use an absolute path to the collections config JSON","Fix file permissions or mount the file into the container running the peer CLI","Validate the JSON structure: an array of collection configs with name, policy, requiredPeerCount etc."],"exampleFix":"// before\npeer chaincode approveformyorg ... --collections-config collections.json\n// after\npeer chaincode approveformyorg ... --collections-config /absolute/path/collections.json","handlingStrategy":"validation","validationCode":"const fs = require('fs');\nfunction assertCollectionsConfig(p) {\n  const cfg = JSON.parse(fs.readFileSync(p, 'utf8'));\n  if (!Array.isArray(cfg)) throw new Error('collections config must be a JSON array');\n  if (cfg.length === 0) throw new Error('collections config array is empty');\n}\nassertCollectionsConfig('/absolute/path/collections.json');","typeGuard":null,"tryCatchPattern":"cfg, sig, err := GetCollectionConfigFromFile(path)\nif err != nil {\n  return fmt.Errorf(\"collections config: %w\", err) // includes could not read file '%s'\n}","preventionTips":["Use absolute paths for --collections-config","Cat/validate the JSON file in CI before deploying chaincode","Mount collection configs explicitly into containers running the peer CLI","Check file permissions and current working directory before CLI calls"],"tags":["cli","file-io","collections-config"],"backgroundTag":"file-not-found","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"}