hyperledger/fabric · error
error decoding input
Error message
error decoding input
What it means
In `encodeProto` (cmd/configtxlator/main.go:143), `protolator.DeepUnmarshalJSON(input, msg)` failed to decode the JSON input file into the target proto message. The JSON either isn't valid JSON or doesn't match the schema/field types of the --type message. configtxlator wraps this as 'error decoding input'.
Source
Thrown at cmd/configtxlator/main.go:143
fmt.Println(metadata.GetVersionInfo())
}
func encodeProto(msgName string, input, output *os.File) error {
mt, err := protoregistry.GlobalTypes.FindMessageByName(protoreflect.FullName(msgName))
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)
err = protolator.DeepUnmarshalJSON(input, msg)
if err != nil {
return errors.Wrapf(err, "error decoding input")
}
if msg == nil {
return errors.New("error marshaling: proto: Marshal called with nil")
}
out, err := proto.Marshal(msg)
if err != nil {
return errors.Wrapf(err, "error marshaling")
}
_, err = output.Write(out)
if err != nil {
return errors.Wrapf(err, "error writing output")
}
return nil
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Validate the input file is well-formed JSON (run it through jq or a JSON linter).
- Ensure --type matches the JSON content (e.g. common.Envelope JSON needs --type common.Envelope, not common.Config).
- Remove unknown fields or re-export the JSON from the same Fabric version's configtxlator proto_decode.
- Confirm you are passing the JSON file (not the .pb binary) to --input.
Example fix
// before: type mismatch $ configtxlator proto_encode --type common.Config --input envelope.json --output out.pb // after: match type to content $ configtxlator proto_encode --type common.Envelope --input envelope.json --output out.pb
Defensive patterns
Strategy: validation
Validate before calling
// Validate JSON parses and matches the expected type before encoding
import json
payload = json.load(open(input_path))
if type_arg == 'common.Envelope' and 'signature' not in payload:
raise SystemExit('input looks like an Envelope but --type is not common.Envelope')
if type_arg == 'common.Config' and 'channel_group' not in payload:
raise SystemExit('input does not look like common.Config') Try / catch
out, err := exec.Command("configtxlator", "proto_encode", "--type", t, "--input", f, "--output", o).CombinedOutput()
if err != nil && strings.Contains(string(out), "error decoding input") {
return fmt.Errorf("JSON in %s does not match %s; run: jq . %s", f, t, f)
} Prevention
- Always produce input JSON via `configtxlator proto_decode` instead of hand-writing it.
- Match --type to the JSON you decoded from — never mix Envelope JSON with common.Config.
- Run `jq . input.json` to catch syntax errors before encoding.
- Avoid editing unknown fields; delete only what you intend to change.
When it happens
Trigger: Running `configtxlator proto_encode` with an input JSON that is syntactically invalid, empty, truncated, contains unknown fields (strict decoding), or whose field types don't match the --type message schema (e.g. passing an Envelope JSON while --type is common.Config).
Common situations: Hand-editing exported JSON and breaking its syntax; encoding with the wrong --type for the JSON content; exporting JSON from a different Fabric proto version; feeding a protobuf binary file instead of JSON.
Related errors
- error encode input
- message of type %s unknown
- error marshaling: proto: Marshal called with nil
- error marshaling
- error writing output
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/f97bbaff955843f0.
Report an issue: GitHub.