Tencent/WeKnora · error

parse ima credentials: %w

Error message

parse ima credentials: %w

What it means

Fires in parseIMAConfig when the JSON roundtrip unmarshal of the credentials into the IMA Config struct fails, meaning the credential JSON does not match the expected IMA schema (wrong types or shape for client_id/api_key fields).

Source

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

	if !strings.Contains(url, "://") {
		url = "https://" + url
	}
	return strings.TrimRight(url, "/")
}

// 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

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify credentials contain client_id and api_key as strings
  2. Remove or correct fields with mismatched JSON types
  3. Extra unknown fields are safe to leave; only typed fields must match
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/datasource/connector/ima/types.go:67 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/b78620be4d9bff9a. Report an issue: GitHub.