Tencent/WeKnora · error

%w: api_key is required

Error message

%w: api_key is required

What it means

Credential validation in parseIMAConfig: the datasource credentials JSON parsed successfully but the api_key field is missing or blank after trimming. The %w wraps datasource.ErrInvalidConfig so callers can classify it as a configuration error; it fires during Validate/ListResources/walk whenever an IMA datasource lacks its API key.

Source

Thrown at internal/datasource/connector/ima/types.go:73

// parseIMAConfig extracts and validates IMA-specific configuration.
// Uses JSON marshal/unmarshal roundtrip so extra fields are ignored gracefully.
func parseIMAConfig(config *types.DataSourceConfig) (*Config, error) {
	if config == nil {
		return nil, fmt.Errorf("%w: config is nil", datasource.ErrInvalidConfig)
	}
	credBytes, err := json.Marshal(config.Credentials)
	if err != nil {
		return nil, fmt.Errorf("marshal credentials: %w", err)
	}
	var cfg Config
	if err := json.Unmarshal(credBytes, &cfg); err != nil {
		return nil, fmt.Errorf("parse ima credentials: %w", err)
	}
	if strings.TrimSpace(cfg.ClientID) == "" {
		return nil, fmt.Errorf("%w: client_id is required", datasource.ErrInvalidCredentials)
	}
	if strings.TrimSpace(cfg.APIKey) == "" {
		return nil, fmt.Errorf("%w: api_key is required", datasource.ErrInvalidCredentials)
	}
	if err := datasource.ValidateConnectorBaseURL(cfg.GetBaseURL()); err != nil {
		return nil, err
	}
	return &cfg, nil
}

// apiEnvelope is the uniform IMA response wrapper: `{ code, msg, data }`.
// A non-zero code is a business-level error and MUST be surfaced to the user.
//
// Some published IMA references spell the same envelope `{ retcode, errmsg }`.
// Accepting both costs nothing and avoids the failure mode where a mismatch
// leaves Code at its zero value and every API error is silently read as
// success.
type apiEnvelope struct {
	Code   int    `json:"code"`
	Msg    string `json:"msg"`
	RetErr *int   `json:"retcode"`

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Provide the api_key in the IMA datasource credentials
  2. Check secret-store injection for empty values
  3. Validate credentials before saving the datasource
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/datasource/connector/ima/types.go:73 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/57210d4f9c7afe63. Report an issue: GitHub.