go-kratos/kratos · error

fileName invalid

Error message

fileName invalid

What it means

Returned by the polaris config source constructor (contrib/config/polaris/config.go:67), immediately after the fileGroup check. options.fileName defaults to "" and only WithFileName sets it; a polaris config file is identified by (namespace, fileGroup, fileName), so an empty fileName makes the FetchConfigFile request in Load() unaddressable and New rejects it up front.

Source

Thrown at contrib/config/polaris/config.go:67

}

func New(client polaris.ConfigAPI, opts ...Option) (config.Source, error) {
	options := &options{
		namespace: "default",
		fileGroup: "",
		fileName:  "",
	}

	for _, opt := range opts {
		opt(options)
	}

	if options.fileGroup == "" {
		return nil, errors.New("fileGroup invalid")
	}

	if options.fileName == "" {
		return nil, errors.New("fileName invalid")
	}

	return &source{
		client:  client,
		options: options,
	}, nil
}

// Load return the config values
func (s *source) Load() ([]*config.KeyValue, error) {
	configFile, err := s.client.FetchConfigFile(&polaris.GetConfigFileRequest{
		GetConfigFileRequest: &model.GetConfigFileRequest{
			Namespace: s.options.namespace,
			FileGroup: s.options.fileGroup,
			FileName:  s.options.fileName,
			Subscribe: true,
		},
	})

View on GitHub (pinned to 668db92c2c)

Solutions

  1. Add polarisConfig.WithFileName with the exact file name created in the polaris console, e.g. WithFileName("config.yaml")
  2. Check the polaris console that the file exists under the same namespace+group you configured

Example fix

// before
src, err := polarisConfig.New(cli, polarisConfig.WithFileGroup("myapp"))
// err = fileName invalid

// after
src, err := polarisConfig.New(cli,
    polarisConfig.WithNamespace("default"),
    polarisConfig.WithFileGroup("myapp"),
    polarisConfig.WithFileName("config.yaml"),
)
Defensive patterns

Strategy: validation

Validate before calling

if fileName == "" {
    return fmt.Errorf("polaris config requires fileName")
}
src, err := polarisConfig.New(cli,
    polarisConfig.WithFileGroup(fileGroup),
    polarisConfig.WithFileName(fileName),
)

Prevention

When it happens

Trigger: Calling polarisConfig.New(cli, polarisConfig.WithFileGroup("mygroup")) without WithFileName; or passing options in the wrong belief that fileName defaults from the client. Any construction where options.fileName is "" fails here.

Common situations: Only supplying the group after copying a half-finished example; renaming the file in the polaris console but not in code (an empty string is the extreme case); passing WithFileName("") from an uninitialized variable.

Related errors


AI-assisted analysis of go-kratos/kratos@668db92c2c (2026-08-16). Data as JSON: /api/errors/83308f6da999830a. Report an issue: GitHub.