hyperledger/fabric · error
filename cannot be empty
Error message
filename cannot be empty
What it means
GetConfig loads a connection profile (network configuration) from a file path; the function requires a non-empty filename. An empty string would attempt a pointless (and failing) file read, so it is rejected immediately with this sentinel error.
Source
Thrown at internal/peer/common/networkconfig.go:160
// Certfiles root certificates for TLS validation (Comma separated path list)
Path string `yaml:"path"`
// Client TLS information
Client TLSKeyPair `yaml:"client"`
}
// TLSKeyPair contains the private key and certificate for TLS encryption
// not currently used by CLI
type TLSKeyPair struct {
Key TLSConfig `yaml:"key"`
Cert TLSConfig `yaml:"cert"`
}
// GetConfig unmarshals the provided connection profile into a network
// configuration struct
func GetConfig(fileName string) (*NetworkConfig, error) {
if fileName == "" {
return nil, errors.New("filename cannot be empty")
}
data, err := os.ReadFile(fileName)
if err != nil {
return nil, errors.Wrap(err, "error reading connection profile")
}
configData := string(data)
config := &NetworkConfig{}
err = yaml.Unmarshal([]byte(configData), &config)
if err != nil {
return nil, errors.Wrap(err, "error unmarshalling YAML")
}
return config, nil
}
View on GitHub (pinned to 2736b63f8f)
Solutions
- Pass the path to a valid connection profile YAML/JSON file
- Check the env var or flag feeding the fileName argument is set and non-empty
- Verify the calling wrapper/CLI parsed the flag correctly
Example fix
// before
profilePath := os.Getenv("CONNECTION_PROFILE") // empty!
nc, err := common.GetConfig(profilePath)
// after
profilePath := os.Getenv("CONNECTION_PROFILE")
if profilePath == "" { log.Fatal("CONNECTION_PROFILE must point to a connection profile file") }
nc, err := common.GetConfig(profilePath) Defensive patterns
Strategy: validation
Validate before calling
if profilePath == "" {
return errors.New("connection profile path is required")
}
if _, err := os.Stat(profilePath); err != nil {
return fmt.Errorf("connection profile not found: %w", err)
} Try / catch
nc, err := common.GetConfig(path)
if err != nil {
if strings.Contains(err.Error(), "filename cannot be empty") {
return errors.New("--connectionProfile flag or its env var was not set")
}
return err
} Prevention
- Always pass --connectionProfile explicitly on CLI calls
- Fail fast in wrapper scripts when the profile path env var is empty
- os.Stat the profile path before invoking GetConfig
When it happens
Trigger: Calling common.GetConfig("") — e.g. the --connectionProfile flag or path variable was never set, an env var like the connection-profile path is empty/unset.
Common situations: Forgetting --connectionProfile on peer CLI commands, an empty configPath field in a wrapper script, env var (e.g. path to the profile YAML) not exported.
Related errors
- chaincode install package must be provided
- %s is mandatory and cannot be empty
- enrollment certificate isn't a valid PEM block
- failed to decode PEM block from %s
- could not create channel %s sub-group config
AI-assisted analysis of hyperledger/fabric@2736b63f8f (2026-09-04).
Data as JSON: /api/errors/1ec022badf3fa44f.
Report an issue: GitHub.