hyperledger/fabric · error
error unmarshalling
Error message
error unmarshalling
What it means
proto.Unmarshal rejected the input bytes while decoding to the requested message type. "error unmarshalling" means the binary data is not a valid wire-format encoding of the --type message (truncated, corrupted, or actually a different message/encoding such as JSON).
Source
Thrown at cmd/configtxlator/main.go:182
if err != nil {
return errors.Wrapf(err, "error encode input")
}
msgType := reflect.TypeOf(mt.Zero().Interface())
if msgType == nil {
return errors.Errorf("message of type %s unknown", msgType)
}
msg := reflect.New(msgType.Elem()).Interface().(proto.Message)
in, err := io.ReadAll(input)
if err != nil {
return errors.Wrapf(err, "error reading input")
}
err = proto.Unmarshal(in, msg)
if err != nil {
return errors.Wrapf(err, "error unmarshalling")
}
err = protolator.DeepMarshalJSON(output, msg)
if err != nil {
return errors.Wrapf(err, "error encoding output")
}
return nil
}
func computeUpdt(original, updated, output *os.File, channelID string) error {
origIn, err := io.ReadAll(original)
if err != nil {
return errors.Wrapf(err, "error reading original config")
}
origConf := &cb.Config{}
err = proto.Unmarshal(origIn, origConf)View on GitHub (pinned to 2736b63f8f)
Solutions
- Confirm input is binary proto, not JSON; use `encode` for JSON→pb and `decode` for pb→JSON
- Validate bytes with `protoc --decode_raw < config.pb` to see actual wire content
- Match the --type to what was originally encoded (common.Config vs common.ConfigUpdate)
- Re-export the config from the ordering service if the file is truncated/corrupt
Example fix
// before configtxlator decode --input config.json --output config.pb --type common.Config // after configtxlator encode --input config.json --output config.pb --type common.Config
Defensive patterns
Strategy: validation
Validate before calling
// sniff binary vs JSON before decode
head -c1 "$INPUT" | grep -q '{' && echo "input is JSON; use encode, not decode" && exit 1 Try / catch
out, err := cmd.CombinedOutput()
if err != nil && strings.Contains(string(out), "error unmarshalling") {
return fmt.Errorf("input is not valid binary proto for the given --type: %w", err)
} Prevention
- Pair encode/decode calls correctly in scripts
- Never hand-edit .pb files; edit JSON and re-encode
- Sanity-check with protoc --decode_raw when unsure
When it happens
Trigger: Feeding a JSON config back into decode (wrong direction), decoding with the wrong --type so fields don't line up, truncated file from a failed export, or base64-encoded bytes not decoded first.
Common situations: Swapping encode/decode flags in scripts, editing a .pb file by hand, pulling a partial block of a channel config, or decoding a ConfigUpdate payload as common.Config.
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
- error unmarshalling original config
- error unmarshalling updated config
- error encoding output
- failed to unmarshal ApplicationPolicy bytes
- could not unmarshal signature policy envelope
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/fa68628a3178aaa5.
Report an issue: GitHub.