hyperledger/fabric · error

malformed org definition for org: %s

Error message

malformed org definition for org: %s

What it means

In `doPrintOrg` (cmd/configtxgen/main.go:131), the Orderer org group was built successfully by `encoder.NewOrdererOrgGroup`, but `protolator.DeepMarshalJSON` failed to render the resulting `DynamicOrdererOrgGroup` config group as JSON. This means the org's config group contains fields that violate the proto schema or dynamic validation rules enforced by protolator. It is a rendering/validation failure, not a config-parsing failure.

Source

Thrown at cmd/configtxgen/main.go:131

		return fmt.Errorf("malformed transaction contents: %s", err)
	}

	return nil
}

func doPrintOrg(t *genesisconfig.TopLevel, printOrg string) error {
	for _, org := range t.Organizations {
		if org.Name == printOrg {
			if len(org.OrdererEndpoints) > 0 {
				// An Orderer OrgGroup
				channelCapabilities := t.Capabilities["Channel"]
				og, err := encoder.NewOrdererOrgGroup(org, channelCapabilities)
				if err != nil {
					return errors.Wrapf(err, "bad org definition for org %s", org.Name)
				}

				if err := protolator.DeepMarshalJSON(os.Stdout, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: og}); err != nil {
					return errors.Wrapf(err, "malformed org definition for org: %s", org.Name)
				}
				return nil
			}

			// Otherwise assume it is an Application OrgGroup, where the encoder is not strict whether anchor peers exist or not
			ag, err := encoder.NewApplicationOrgGroup(org)
			if err != nil {
				return errors.Wrapf(err, "bad org definition for org %s", org.Name)
			}
			if err := protolator.DeepMarshalJSON(os.Stdout, &peerext.DynamicApplicationOrgGroup{ConfigGroup: ag}); err != nil {
				return errors.Wrapf(err, "malformed org definition for org: %s", org.Name)
			}
			return nil
		}
	}
	return errors.Errorf("organization %s not found", printOrg)
}

View on GitHub (pinned to 2736b63f8f)

Solutions

  1. Inspect the wrapped inner error printed alongside this message to find the exact field that failed deep JSON marshaling.
  2. Fix the org definition in configtx.yaml (OrdererOrgs section) so it conforms to the expected schema (correct MSPDir/OUs/Endpoint fields).
  3. Regenerate the org group with a clean configtx.yaml rather than hand-editing intermediate JSON.
  4. If migrating from an older Fabric version, re-validate the org config against the current encoder (encoder.NewOrdererOrgGroup) expectations.

Example fix

// configtx.yaml before (malformed Orderer org)
OrdererOrgs:
  - Name: OrdererOrg
    Domain: example.com
    Endpoint:   # invalid/misspelled nested field can break deep marshaling
      - badField: x
// after
OrdererOrgs:
  - Name: OrdererOrg
    Domain: example.com
    EnableNodeOUs: true
    Specs:
      - Hostname: orderer
Defensive patterns

Strategy: validation

Validate before calling

// Validate the org resolves and its Orderer group marshals before printing
og, err := encoder.NewOrdererOrgGroup(org, channelCapabilities)
if err != nil {
	return fmt.Errorf("org %s invalid for orderer encoding: %w", org.Name, err)
}
if err := protolator.DeepMarshalJSON(io.Discard, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: og}); err != nil {
	return fmt.Errorf("org %s fails JSON marshaling: %w", org.Name, err)
}

Try / catch

// Go: check and wrap the underlying cause
if err := protolator.DeepMarshalJSON(os.Stdout, &ordererext.DynamicOrdererOrgGroup{ConfigGroup: og}); err != nil {
	log.Fatalf("org %s: %v", org.Name, errors.Unwrap(err))
}

Prevention

When it happens

Trigger: Running `configtxgen -printOrg <org>` where the org resolves to an Orderer org whose generated ConfigGroup fails protolator's deep JSON marshaling (e.g. inconsistent sub-group structure, invalid nested field types, or a bad value that passed the encoder but fails proto dynamic validation).

Common situations: Hand-edited or tool-generated configtx.yaml with subtly malformed org fields; org definitions migrated from older Fabric versions whose nested group structure no longer marshals cleanly; corrupted intermediate config produced by an upstream tool.

Understand the failure class

Related errors


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