dianping/cat · error
Only 1 config can be specified while initializing cat.
Error message
Only 1 config can be specified while initializing cat.
What it means
gocat's Init panics when more than one Config value is passed via its variadic parameter. The API is designed so callers either pass no config (defaults are used), or exactly one Config; multiple configs are ambiguous so the library aborts immediately rather than guessing. The panic occurs before ccat.InitWithConfig is ever called, so nothing is initialized when it fires.
Source
Thrown at lib/go/gocat/cat.go:55
1,
0,
}
}
func DefaultConfigForCat2() Config {
return Config{
ENCODER_TEXT,
1,
0,
0,
}
}
func Init(domain string, configs ...Config) {
var config Config;
if len(configs) > 1 {
panic("Only 1 config can be specified while initializing cat.")
} else if len(configs) == 1 {
config = configs[0]
} else {
config = DefaultConfig()
}
ccat.InitWithConfig(domain, ccat.BuildConfig(
config.EncoderType,
config.EnableHeartbeat,
config.EnableSampling,
config.EnableDebugLog,
))
go ccat.Background()
}
func Shutdown() {
ccat.Shutdown()
}View on GitHub (pinned to e815e74d4c)
Solutions
- Pass at most one Config: merge the desired options into a single Config value before calling Init
- Or call Init(domain) with no config to accept DefaultConfig() (text encoder, heartbeat on, sampling/debug off)
- Use recover() around Init during development if the config count comes from dynamic code
Example fix
// before
gocat.Init("mydomain", gocat.Config{gocat.ENCODER_TEXT, 1, 0, 0},
gocat.Config{gocat.ENCODER_BINARY, 0, 1, 0})
// after
gocat.Init("mydomain", gocat.Config{
EncoderType: gocat.ENCODER_TEXT,
EnableHeartbeat: 1,
EnableSampling: 0,
EnableDebugLog: 0,
}) Defensive patterns
Strategy: validation
Validate before calling
func safeInit(domain string, configs ...gocat.Config) {
if len(configs) > 1 {
cfg := configs[0] // merge or pick explicitly instead of panicking
log.Printf("gocat: ignoring extra configs (%d passed, 1 allowed)", len(configs))
gocat.Init(domain, cfg)
return
}
gocat.Init(domain, configs...)
} Type guard
func isValidInitArgs(domain string, configs []gocat.Config) bool {
return domain != "" && len(configs) <= 1
} Try / catch
defer func() {
if r := recover(); r != nil {
log.Fatalf("gocat init failed: %v", r)
}
}()
gocat.Init("mydomain", cfg1, cfg2) Prevention
- Build one Config struct with all desired fields instead of passing multiple Configs
- Call gocat.Init exactly once at process start, from a single init function
- Remember Init with zero configs is valid and applies DefaultConfig()
When it happens
Trigger: Calling gocat.Init(domain, cfg1, cfg2) with two or more Config arguments, e.g. trying to combine a text-encoder config and a heartbeat-enabled config instead of building a single Config with all fields set.
Common situations: New Go users assume Configs are composable and pass several to enable multiple options; refactoring code where configs from different call sites got concatenated into one Init call; copying sample code that built a Config and appending another 'just in case'.
Related errors
- Please supply an object of options
- Invalid argument length
- button key {key} is not allowed (options are {buttons})
- Unsupported message type: %s.
- Invalid message ID format: %s
AI-assisted analysis of dianping/cat@e815e74d4c (2026-08-14).
Data as JSON: /api/errors/fd538fd34ebc6b36.
Report an issue: GitHub.