hyperledger/fabric · error
expected two space separated tokens, but got %d
Error message
expected two space separated tokens, but got %d
What it means
ImplicitMetaFromString parses strings like 'ANY Readers' into an ImplicitMetaPolicy proto. It splits the input on spaces and requires exactly two tokens (rule + sub-policy name); any other token count throws this error.
Source
Thrown at common/policies/implicitmetaparser.go:19
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package policies
import (
"strings"
cb "github.com/hyperledger/fabric-protos-go-apiv2/common"
"github.com/pkg/errors"
)
func ImplicitMetaFromString(input string) (*cb.ImplicitMetaPolicy, error) {
args := strings.Split(input, " ")
if len(args) != 2 {
return nil, errors.Errorf("expected two space separated tokens, but got %d", len(args))
}
res := &cb.ImplicitMetaPolicy{
SubPolicy: args[1],
}
switch args[0] {
case cb.ImplicitMetaPolicy_ANY.String():
res.Rule = cb.ImplicitMetaPolicy_ANY
case cb.ImplicitMetaPolicy_ALL.String():
res.Rule = cb.ImplicitMetaPolicy_ALL
case cb.ImplicitMetaPolicy_MAJORITY.String():
res.Rule = cb.ImplicitMetaPolicy_MAJORITY
default:
return nil, errors.Errorf("unknown rule type '%s', expected ALL, ANY, or MAJORITY", args[0])
}
return res, nilView on GitHub (pinned to 2736b63f8f)
Solutions
- Supply exactly two space-separated tokens: a rule (ALL/ANY/MAJORITY) and a sub-policy name, e.g. 'ANY Readers'
- Trim surrounding whitespace and remove extra spaces/tabs from the policy string
- Check the policy value in configtx.yaml or channel update config for typos or missing sub-policy name
Example fix
// before
ImplicitMetaFromString("MAJORITY")
// after
ImplicitMetaFromString("MAJORITY Admins") Defensive patterns
Strategy: validation
Validate before calling
func validImplicitMeta(s string) bool {
parts := strings.Fields(s)
return len(parts) == 2 &&
(parts[0] == "ALL" || parts[0] == "ANY" || parts[0] == "MAJORITY")
}
// call ImplicitMetaFromString only if validImplicitMeta(input) Try / catch
policy, err := policies.ImplicitMetaFromString(input)
if err != nil && strings.Contains(err.Error(), "expected two space separated tokens") {
return fmt.Errorf("invalid implicit meta policy %q: use 'RULE SubPolicy'", input)
} Prevention
- Always write policies as exactly 'RULE SubPolicy' with single spaces
- Trim and normalize whitespace before parsing
- Never omit the sub-policy name in configtx policy expressions
When it happens
Trigger: Calling ImplicitMetaFromString with a string that does not contain exactly one space-separated pair, e.g. 'READERS', 'ANY Writers extra', or a value with tabs/multiple spaces collapsing incorrectly.
Common situations: Typo or omission in channel config policy values like 'MAJORITY' without the sub-policy name; copying a policy string with an accidental extra word; programmatic construction with an empty or trimmed-to-empty input.
Related errors
- unknown rule type '%s', expected ALL, ANY, or MAJORITY
- policy %s at path %s was nil
- implicit policy %s at path %s did not compile
- not a valid hashedDataNs [%s]
- could not parse RevocationList
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/8fe92f3e6c9e0b7d.
Report an issue: GitHub.