hyperledger/fabric · error
panic(err)
Error message
panic(err)
What it means
UnmarshalConfigOrPanic wraps UnmarshalConfig and panics instead of returning an error when the input bytes cannot be unmarshaled into a *cb.Config protobuf. This library uses *OrPanic variants for call sites where a failure indicates a programmer error or corrupted internal data that makes recovery impossible. The panic carries the underlying unmarshal error from the protobuf layer.
Source
Thrown at common/configtx/util.go:29
"github.com/hyperledger/fabric/protoutil"
"google.golang.org/protobuf/proto"
)
// UnmarshalConfig attempts to unmarshal bytes to a *cb.Config
func UnmarshalConfig(data []byte) (*cb.Config, error) {
config := &cb.Config{}
err := proto.Unmarshal(data, config)
if err != nil {
return nil, err
}
return config, nil
}
// UnmarshalConfigOrPanic attempts to unmarshal bytes to a *cb.Config or panics on error
func UnmarshalConfigOrPanic(data []byte) *cb.Config {
result, err := UnmarshalConfig(data)
if err != nil {
panic(err)
}
return result
}
// UnmarshalConfigUpdate attempts to unmarshal bytes to a *cb.ConfigUpdate
func UnmarshalConfigUpdate(data []byte) (*cb.ConfigUpdate, error) {
configUpdate := &cb.ConfigUpdate{}
err := proto.Unmarshal(data, configUpdate)
if err != nil {
return nil, err
}
return configUpdate, nil
}
// UnmarshalConfigUpdateOrPanic attempts to unmarshal bytes to a *cb.ConfigUpdate or panics on error
func UnmarshalConfigUpdateOrPanic(data []byte) *cb.ConfigUpdate {
result, err := UnmarshalConfigUpdate(data)
if err != nil {View on GitHub (pinned to 2736b63f8f)
Solutions
- Validate the bytes with UnmarshalConfig (the non-panic variant) first and handle the error instead of using the OrPanic wrapper
- Verify the input is the Config field from a ConfigEnvelope, not ConfigUpdate or envelope bytes
- Re-fetch the config block from a trusted source (orderer/peer) rather than a local copy that may be corrupt
- If the bytes come from a configtxgen-generated file, regenerate it with the matching Fabric version
Example fix
// before
config := configtx.UnmarshalConfigOrPanic(rawBytes)
// after
config, err := configtx.UnmarshalConfig(rawBytes)
if err != nil {
return fmt.Errorf("invalid config bytes: %w", err)
} Defensive patterns
Strategy: try-catch
Validate before calling
if len(data) == 0 {
return errors.New("config bytes are empty")
}
probe := &cb.Config{}
if err := proto.Unmarshal(data, probe); err != nil {
return fmt.Errorf("not a valid Config: %w", err)
} Type guard
func looksLikeConfig(data []byte) bool {
probe := &cb.Config{}
return len(data) > 0 && proto.Unmarshal(data, probe) == nil
} Try / catch
defer func() {
if r := recover(); r != nil {
err = fmt.Errorf("UnmarshalConfigOrPanic failed: %v", r)
}
}()
config := configtx.UnmarshalConfigOrPanic(data) Prevention
- Prefer the error-returning UnmarshalConfig in application code; reserve OrPanic for internal invariants
- Never pass user-supplied bytes directly to the OrPanic variant
- Validate payload header type before unmarshaling config data
- Keep Fabric versions aligned across tools that produce and consume config bytes
When it happens
Trigger: Calling UnmarshalConfigOrPanic with nil bytes, truncated data, non-Config protobuf bytes, or bytes corrupted after a version change of the cb.Config message schema.
Common situations: Reading a config block from a badly corrupted or hand-edited ledger file; passing the wrong envelope field (e.g. ConfigUpdate bytes instead of Config bytes) to the helper; upgrading Fabric versions where stored config serialization assumptions changed.
Understand the failure class
Background: "cannot parse invalid wire-format data", "cannot unmarshal", "failed unmarshalling": protobuf unmarshal errors explained — this error's family across 10 libraries.
Related errors
- failed to deserialize values
- Error unmarshalling to ImplicitMetaPolicy: %s
- failed to unmarshal envelope from bytes
- error getting deployment spec
- failed to deserialize proposal response payload
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/2625db2f48a4288f.
Report an issue: GitHub.