go-kratos/kratos · error
path invalid
Error message
path invalid
What it means
Returned by etcd.New in the etcd config source (contrib/config/etcd/config.go:61). The constructor defaults path:"" and requires the WithPath option; without it there is no key prefix to query, so New fails immediately. Identical shape to the consul source's path validation - a constructor-time guard, unrelated to etcd connectivity.
Source
Thrown at contrib/config/etcd/config.go:61
type source struct {
client *clientv3.Client
options *options
}
func New(client *clientv3.Client, opts ...Option) (config.Source, error) {
options := &options{
ctx: context.Background(),
path: "",
prefix: false,
}
for _, opt := range opts {
opt(options)
}
if options.path == "" {
return nil, errors.New("path invalid")
}
return &source{
client: client,
options: options,
}, nil
}
// Load return the config values
func (s *source) Load() ([]*config.KeyValue, error) {
var opts []clientv3.OpOption
if s.options.prefix {
opts = append(opts, clientv3.WithPrefix())
}
rsp, err := s.client.Get(s.options.ctx, s.options.path, opts...)
if err != nil {
return nil, errView on GitHub (pinned to 668db92c2c)
Solutions
- Pass etcd.WithPath with the key prefix holding your config, e.g. etcd.New(client, etcd.WithPath("/kratos/app/config"))
- If using WithPrefix(true), remember path is still required as the prefix root
- Verify keys exist: etcdctl get --prefix /kratos/app/config
Example fix
// before
src, err := etcd.New(client)
// err = path invalid
// after
src, err := etcd.New(client, etcd.WithPath("/kratos/app/config")) Defensive patterns
Strategy: validation
Validate before calling
if path == "" {
return fmt.Errorf("etcd config source requires a key prefix")
}
src, err := etcd.New(client, etcd.WithPath(path), etcd.WithPrefix(true)) Prevention
- Treat etcd.WithPath as required; WithPrefix never substitutes for it
- Centralize source construction in one config package per app
- Assert in tests that New(client, prodOpts...) returns nil error
When it happens
Trigger: Calling etcd.New(clientv3Client) with no options, or with only WithContext/WithPrefix but no etcd.WithPath. Any call where options.path remains "" returns this error before any etcd RPC is made.
Common situations: Example snippets that show only client creation; enabling prefix mode via etcd.WithPrefix(true) but forgetting the base path it prefixes; refactor dropping the option during migration from another config source.
Related errors
AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16).
Data as JSON: /api/errors/0f2dfc1a375606ca.
Report an issue: GitHub.