{"record":{"id":"18786031a2d7ec1e","repo":"hyperledger/fabric","slug":"connection-json-not-found-in-source-folder-s","errorCode":null,"errorMessage":"connection.json not found in source folder: %s","messagePattern":"connection\\.json not found in source folder: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ccaas_builder/cmd/release/main.go","lineNumber":71,"sourceCode":"\n\tbuilderOutputDir, releaseDir := os.Args[1], os.Args[2]\n\tconnectionSrcFile := filepath.Join(builderOutputDir, \"/connection.json\")\n\n\tconnectionDir := filepath.Join(releaseDir, \"chaincode/server/\")\n\tconnectionDestFile := filepath.Join(releaseDir, \"chaincode/server/connection.json\")\n\n\tmetadataDir := filepath.Join(builderOutputDir, \"META-INF/statedb\")\n\tmetadataDestDir := filepath.Join(releaseDir, \"statedb\")\n\tif _, err := os.Stat(metadataDir); !os.IsNotExist(err) {\n\t\tif err := copy.Copy(metadataDir, metadataDestDir); err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy metadataDir directory folder: %s\", err)\n\t\t}\n\t}\n\n\t// Process and update the connections file\n\t_, err := os.Stat(connectionSrcFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"connection.json not found in source folder: %s\", err)\n\t}\n\n\terr = os.MkdirAll(connectionDir, 0o750)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create target folder for connection.json: %s\", err)\n\t}\n\n\tif err = Copy(connectionSrcFile, connectionDestFile); err != nil {\n\t\treturn err\n\t}\n\n\treturn nil\n}\n\n// Copy the src file to dst. Any existing file will be overwritten and will not\n// copy file attributes.\nfunc Copy(src, dst string) error {\n\tin, err := os.Open(src)","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/ccaas_builder/cmd/release/main.go#L53-L89","documentation":"batchRetrieveDocumentMetadata() builds the {\"keys\": [...]} request body with json.Marshal before POSTing to _all_docs. If marshalling fails the error is wrapped as 'error marshalling json data' and the batch read fails. json.Marshal of a []string of keys can only fail in exotic conditions (keys derived from unsupported types); this typically points to a bug in key construction rather than CouchDB.","triggerScenarios":"Calling BatchRetrieveDocumentMetadata with keys whose marshalling fails — e.g. keys slice containing non-encodable values due to upstream type corruption, or a custom build where keymap gained non-string entries.","commonSituations":"Extremely rare in stock Fabric; seen in forks/patches that widen the keys parameter type, or instrumentation that inserts unsupported values into the keymap.","solutions":["Confirm keys is a []string with plain string content; log the slice before marshalling","If keys come from a custom serializer, verify they decode as valid UTF-8 strings","Reproduce the underlying json.Marshal error directly on the keymap to see the exact unsupported type","Revert or fix any fork modifications to batchRetrieveDocumentMetadata","Upgrade to an unmodified Fabric release for this code path"],"exampleFix":"// before\nkeymap[\"keys\"] = interfaceSliceOfUnknownTypes // may contain unsupported values\n// after\nkeys := make([]string, 0, len(rawKeys))\nfor _, k := range rawKeys {\n    keys = append(keys, fmt.Sprintf(\"%v\", k)) // force plain strings\n}\nkeymap[\"keys\"] = keys","handlingStrategy":"validation","validationCode":"for i, k := range keys {\n    if k == \"\" || !utf8.ValidString(k) {\n        return fmt.Errorf(\"invalid key at index %d\", i)\n    }\n}\nif _, err := json.Marshal(map[string]any{\"keys\": keys}); err != nil {\n    return err\n}","typeGuard":"func allStrings(v []any) bool {\n    for _, x := range v {\n        if _, ok := x.(string); !ok { return false }\n    }\n    return true\n}","tryCatchPattern":"if err != nil && strings.Contains(err.Error(), \"error marshalling json data\") {\n    return fmt.Errorf(\"batch keys not marshallable — check key construction: %w\", err)\n}","preventionTips":["Keep keys as plain []string end to end","Avoid forks that widen the keys parameter type","Unit-test key construction with json.Marshal before submitting batches","Sanitize keys to valid UTF-8 strings","Treat this error as a code bug, not an operational issue"],"tags":["couchdb","json","marshal","fabric"],"backgroundTag":"json-marshal-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"}