{"record":{"id":"9d01c2d89cfcd6da","repo":"hyperledger/fabric","slug":"could-not-decode-bccsp-type","errorCode":null,"errorMessage":"could not decode bccsp type","messagePattern":"could not decode bccsp type","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/viperutil/config_util.go","lineNumber":369,"sourceCode":"\t\t\treturn result, nil\n\t\tcase ok:\n\t\t\t// fileName was nil\n\t\t\treturn nil, fmt.Errorf(\"Value of File: was nil\")\n\t\t}\n\t}\n\treturn data, nil\n}\n\nfunc bccspHook(f reflect.Type, t reflect.Type, data any) (any, error) {\n\tif t != reflect.TypeFor[*factory.FactoryOpts]() {\n\t\treturn data, nil\n\t}\n\n\tconfig := factory.GetDefaultOpts()\n\n\terr := mapstructure.WeakDecode(data, config)\n\tif err != nil {\n\t\treturn nil, errors.Wrap(err, \"could not decode bccsp type\")\n\t}\n\n\treturn config, nil\n}\n\n// EnhancedExactUnmarshal is intended to unmarshal a config file into a structure\n// producing error when extraneous variables are introduced and supporting\n// the time.Duration type\nfunc (c *ConfigParser) EnhancedExactUnmarshal(output any) error {\n\toType := reflect.TypeOf(output)\n\tif oType.Kind() != reflect.Pointer {\n\t\treturn errors.Errorf(\"supplied output argument must be a pointer to a struct but is not pointer\")\n\t}\n\teType := oType.Elem()\n\tif eType.Kind() != reflect.Struct {\n\t\treturn errors.Errorf(\"supplied output argument must be a pointer to a struct, but it is pointer to something else\")\n\t}\n","sourceCodeStart":351,"sourceCodeEnd":387,"githubUrl":"https://github.com/hyperledger/fabric/blob/2736b63f8fd5932511d56fe68b7039d15977f7f6/common/viperutil/config_util.go#L351-L387","documentation":"bccspHook decodes the bccsp config section (map[string]any from viper) into the factory's default options struct using mapstructure.WeakDecode. If the supplied data cannot be weakly decoded into factory.GetDefaultOpts()'s fields (type mismatch, wrong nesting), the decode error is wrapped with this message. It indicates the bccsp section of the config does not match the expected BCCSP factory option structure.","triggerScenarios":"Calling ConfigParser.EnhancedExactUnmarshal (or Unmarshal) with a config whose 'bccsp' section has keys/values incompatible with factory FactoryOpts fields — e.g. bccsp: set to a string, or Default/Software/SCCProvider keys with wrong types.","commonSituations":"Operators replace core.yaml with an older/newer Fabric version's bccsp schema; typo like 'bccsp: SW' instead of a mapping; env vars like BCCSP_DEFAULT set to values that clash with YAML mapping; copying fabric-ca bccsp config into peer core.yaml.","solutions":["Ensure the bccsp section is a mapping like {Default: SW, SW: {Hash: SHA2, Security: 256, FileKeyStore: {KeyStore: <path>}}}.","Compare your bccsp block against the sample core.yaml for your Fabric version and fix schema drift.","Remove conflicting BCCSP_* env overrides or make their types consistent with the YAML mapping.","Read the wrapped underlying error in the log for the exact field that failed to decode."],"exampleFix":"# before\nbccsp: SW\n# after\nbccsp:\n  Default: SW\n  SW:\n    Hash: SHA2\n    Security: 256\n    FileKeyStore:\n      KeyStore:","handlingStrategy":"validation","validationCode":"bccsp, ok := raw[\"bccsp\"].(map[string]any)\nif !ok {\n    return fmt.Errorf(\"bccsp section must be a mapping like {Default: SW, SW: {...}}\")\n}","typeGuard":"func isBCCSPMapping(v any) bool {\n    _, ok := v.(map[string]any)\n    return ok\n}","tryCatchPattern":null,"preventionTips":["Copy the bccsp block from the official sample core.yaml for your Fabric version","Keep BCCSP_* env vars consistent with the YAML mapping types","Log and read the wrapped mapstructure error to identify the exact offending field"],"tags":["config","bccsp","crypto","mapstructure"],"backgroundTag":"config-decode-type-mismatch","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"}