hyperledger/fabric · error
incorrect number of arguments
Error message
incorrect number of arguments
What it means
ApplyDatabaseSecurity() serializes the databaseSecurity struct with json.Marshal before PUTting it to the database's _security endpoint. If marshalling fails the error is wrapped (with a slightly misleading 'unmarshalling' wording) as 'error unmarshalling json data' and the security update is aborted. json.Marshal only fails for unsupported types (channels, funcs, cyclic structures), so this almost always indicates a bug in the constructed databaseSecurity value rather than a server problem.
Source
Thrown at ccaas_builder/cmd/release/main.go:51
ClientAuth bool `json:"client_auth_required"`
RootCert string `json:"root_cert"`
ClientKey string `json:"client_key"`
ClientCert string `json:"client_cert"`
}
func main() {
logger.Println("::Release")
if err := run(); err != nil {
logger.Printf("::Error: %v\n", err)
os.Exit(1)
}
logger.Printf("::Release phase completed")
}
func run() error {
if len(os.Args) < 3 {
return errors.New("incorrect number of arguments")
}
builderOutputDir, releaseDir := os.Args[1], os.Args[2]
connectionSrcFile := filepath.Join(builderOutputDir, "/connection.json")
connectionDir := filepath.Join(releaseDir, "chaincode/server/")
connectionDestFile := filepath.Join(releaseDir, "chaincode/server/connection.json")
metadataDir := filepath.Join(builderOutputDir, "META-INF/statedb")
metadataDestDir := filepath.Join(releaseDir, "statedb")
if _, err := os.Stat(metadataDir); !os.IsNotExist(err) {
if err := copy.Copy(metadataDir, metadataDestDir); err != nil {
return fmt.Errorf("failed to copy metadataDir directory folder: %s", err)
}
}
// Process and update the connections file
_, err := os.Stat(connectionSrcFile)View on GitHub (pinned to 2736b63f8f)
Solutions
- Inspect the databaseSecurity value passed in; remove any channel, func, or cyclic reference
- Ensure Admins/Members Names/Roles are plain []string slices
- Reproduce with json.Marshal(databaseSecurity) in isolation to see the underlying unsupported-type error
- If extending the struct, add custom MarshalJSON for unsupported fields
- Report as a Fabric bug if it occurs with stock code — stock structs should never fail to marshal
Example fix
// before
type databaseSecurity struct {
Admins admins `json:"admins"`
Conn net.Conn `json:"-"` // func/channel-like field breaks Marshal
}
// after
type databaseSecurity struct {
Admins admins `json:"admins"`
// drop non-serializable fields entirely
} Defensive patterns
Strategy: validation
Validate before calling
if _, err := json.Marshal(databaseSecurity); err != nil {
return fmt.Errorf("security struct not marshallable: %w", err)
} Try / catch
err := db.ApplyDatabaseSecurity(sec)
if err != nil && strings.Contains(err.Error(), "json data") {
return fmt.Errorf("invalid security struct (check for channels/funcs/cycles): %w", err)
} Prevention
- Keep databaseSecurity fields limited to strings and []string
- Never store channels, funcs, or cyclic pointers in request structs
- Unit-test custom security-struct construction with json.Marshal
- Avoid fork modifications to the security struct
- Treat occurrences with stock code as an upstream bug report
When it happens
Trigger: Calling ApplyDatabaseSecurity() with a databaseSecurity struct that contains a value json.Marshal cannot encode — e.g. cyclic pointer references, a channel/func field, or NaN/infinite float values inside the struct.
Common situations: Custom code building security structs with non-serializable fields; plugins or chaincode-injected values with cycles; Go version/type changes introducing unsupported types.
Understand the failure class
Background: json.Marshal / "failed to marshal" errors in Go: why "unsupported type" happens and how to fix it — this error's family across 22 libraries.
Related errors
- connection.json not found in source folder: %s
- failed to marshal config
- too few arguments
- Failed opening file %s: %v
- config isn't valid
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/322c5b824b00224e.
Report an issue: GitHub.