hyperledger/fabric · error

could not decode bccsp type

Error message

could not decode bccsp type

What it means

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.

Source

Thrown at common/viperutil/config_util.go:369

			return result, nil
		case ok:
			// fileName was nil
			return nil, fmt.Errorf("Value of File: was nil")
		}
	}
	return data, nil
}

func bccspHook(f reflect.Type, t reflect.Type, data any) (any, error) {
	if t != reflect.TypeFor[*factory.FactoryOpts]() {
		return data, nil
	}

	config := factory.GetDefaultOpts()

	err := mapstructure.WeakDecode(data, config)
	if err != nil {
		return nil, errors.Wrap(err, "could not decode bccsp type")
	}

	return config, nil
}

// EnhancedExactUnmarshal is intended to unmarshal a config file into a structure
// producing error when extraneous variables are introduced and supporting
// the time.Duration type
func (c *ConfigParser) EnhancedExactUnmarshal(output any) error {
	oType := reflect.TypeOf(output)
	if oType.Kind() != reflect.Pointer {
		return errors.Errorf("supplied output argument must be a pointer to a struct but is not pointer")
	}
	eType := oType.Elem()
	if eType.Kind() != reflect.Struct {
		return errors.Errorf("supplied output argument must be a pointer to a struct, but it is pointer to something else")
	}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Ensure the bccsp section is a mapping like {Default: SW, SW: {Hash: SHA2, Security: 256, FileKeyStore: {KeyStore: <path>}}}.
  2. Compare your bccsp block against the sample core.yaml for your Fabric version and fix schema drift.
  3. Remove conflicting BCCSP_* env overrides or make their types consistent with the YAML mapping.
  4. Read the wrapped underlying error in the log for the exact field that failed to decode.

Example fix

# before
bccsp: SW
# after
bccsp:
  Default: SW
  SW:
    Hash: SHA2
    Security: 256
    FileKeyStore:
      KeyStore:
Defensive patterns

Strategy: validation

Validate before calling

bccsp, ok := raw["bccsp"].(map[string]any)
if !ok {
    return fmt.Errorf("bccsp section must be a mapping like {Default: SW, SW: {...}}")
}

Type guard

func isBCCSPMapping(v any) bool {
    _, ok := v.(map[string]any)
    return ok
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04). Data as JSON: /api/errors/9d01c2d89cfcd6da. Report an issue: GitHub.