{"record":{"id":"26b0bbdb81bbff45","repo":"hyperledger/fabric","slug":"too-few-arguments","errorCode":null,"errorMessage":"too few arguments","messagePattern":"too few arguments","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"ccaas_builder/cmd/detect/main.go","lineNumber":39,"sourceCode":"\nfunc main() {\n\tlogger.Println(\"::Detect\")\n\n\tif err := run(); err != nil {\n\t\tlogger.Printf(\"::Error: %v\\n\", err)\n\t\tos.Exit(1)\n\t}\n\n\tlogger.Printf(\"::Type detected as ccaas\")\n}\n\ntype chaincodeMetadata struct {\n\tType string `json:\"type\"`\n}\n\nfunc run() error {\n\tif len(os.Args) < 3 {\n\t\treturn errors.New(\"too few arguments\")\n\t}\n\n\tchaincodeMetaData := os.Args[2]\n\n\t// Check metadata file's existence\n\tmetadataFile := filepath.Join(chaincodeMetaData, \"metadata.json\")\n\tif _, err := os.Stat(metadataFile); err != nil {\n\t\treturn errors.WithMessagef(err, \"%s not found \", metadataFile)\n\t}\n\n\t// Read the metadata file\n\tmdbytes, err := os.ReadFile(metadataFile)\n\tif err != nil {\n\t\treturn errors.WithMessagef(err, \"%s not readable\", metadataFile)\n\t}\n\n\tvar metadata chaincodeMetadata\n\terr = json.Unmarshal(mdbytes, &metadata)","sourceCodeStart":21,"sourceCodeEnd":57,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/ccaas_builder/cmd/detect/main.go#L21-L57","documentation":"In Hyperledger Fabric's statecouchdb package, GetDatabaseSecurity() fetches a database's _security document from CouchDB and decodes it into a databaseSecurity struct. If the raw HTTP response body is not valid JSON or does not match the expected struct (e.g. non-string members where []string are expected), json.Unmarshal fails and the error is wrapped as 'error unmarshalling json data'. This aborts the security-read operation.","triggerScenarios":"Calling GetDatabaseSecurity() when the CouchDB server returns a body that is not valid JSON (e.g. an HTML error page from a proxy, or a malformed/truncated _security response), or JSON whose shape does not fit databaseSecurity (admins/members names/roles fields of unexpected types).","commonSituations":"A reverse proxy or load balancer intercepting CouchDB traffic and returning HTML; CouchDB returning an error body for an unauthorized request that the client still tries to decode; corrupted or non-JSON response due to network interruption.","solutions":["Verify CouchDB is reachable directly and the URL/credentials are correct so it returns real JSON, not a proxy error page","curl the _security endpoint (GET http://<couchdb>:5984/<db>/_security) and confirm the body is valid JSON matching {admins:{names:[],roles:[]},members:{...}}","Check for a proxy/middleware rewriting the response; bypass it for the CouchDB host","Check Fabric and CouchDB version compatibility","Enable debug logging (couchdbLogger) to inspect the raw response"],"exampleFix":"// before\nresp, err := http.Get(\"http://proxy:80/couchdb/db/_security\") // proxy returns HTML\njson.Unmarshal(raw, jsonResponse) // fails\n// after\nclient := &http.Client{} // point directly at CouchDB, or check Content-Type first\nresp, err := client.Get(\"http://couchdb:5984/db/_security\")\nif ct := resp.Header.Get(\"Content-Type\"); !strings.HasPrefix(ct, \"application/json\") {\n    return nil, errors.New(\"non-JSON response from CouchDB\")\n}","handlingStrategy":"type-guard","validationCode":"raw, _ := io.ReadAll(resp.Body)\nif !json.Valid(raw) {\n    return fmt.Errorf(\"non-JSON _security response: %.200s\", raw)\n}","typeGuard":"func isJSON(b []byte) bool {\n    var v any\n    return json.Unmarshal(b, &v) == nil\n}","tryCatchPattern":"sec, err := db.GetDatabaseSecurity()\nif err != nil {\n    if strings.Contains(err.Error(), \"error unmarshalling json data\") {\n        // log raw response, check CouchDB reachability/auth, retry\n        return fmt.Errorf(\"couchdb returned non-JSON security doc: %w\", err)\n    }\n    return err\n}","preventionTips":["Point the peer directly at CouchDB, not through a rewriting proxy","Verify credentials so CouchDB returns JSON, not HTML error pages","Periodically curl _security to confirm the response shape","Pin compatible Fabric/CouchDB versions","Watch peer logs for repeated unmarshal failures on the same DB"],"tags":["couchdb","json","unmarshal","fabric"],"backgroundTag":"json-unmarshal-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"}