Tencent/WeKnora · error

ErrInvalidConfig

ErrInvalidConfig

Error message

%w: config is nil

What it means

parseConfig in the RSS connector wraps datasource.ErrInvalidConfig when it is handed a nil *types.DataSourceConfig. The wrapper refuses to do any work because there is no configuration object at all to extract feed URLs or credentials from. Callers (Validate, ListResources, walk) should never pass nil; this is a defensive guard.

Source

Thrown at internal/datasource/connector/rss/types.go:57

// Config holds RSS-specific configuration.
//
// FeedURLs are stored in DataSourceConfig.Settings (non-secret, editable in
// the UI without replacing credentials). AuthHeaders live in Credentials
// because they may carry secrets that must be encrypted at rest. Credentials
// may still carry feed_urls for backward compatibility with older rows.
type Config struct {
	// FeedURLs is a newline- or comma-separated list of feed URLs.
	FeedURLs string `json:"feed_urls"`

	// AuthHeaders is an optional newline-separated list of custom request
	// headers in "Name: Value" form, applied only to feed fetches.
	AuthHeaders string `json:"auth_headers,omitempty"`
}

// parseConfig extracts and validates RSS configuration.
func parseConfig(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 rss credentials: %w", err)
	}
	if urls := feedURLsFromSettings(config.Settings); urls != "" {
		cfg.FeedURLs = urls
	}
	if len(cfg.feedURLList()) == 0 {
		return nil, fmt.Errorf("%w: feed_urls is required", datasource.ErrInvalidCredentials)
	}
	return &cfg, nil
}

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Ensure the caller constructs and passes a non-nil *types.DataSourceConfig before invoking the connector.
  2. Check where the DataSourceConfig is loaded (DB/HTTP) and treat a missing config as an earlier, user-facing validation failure instead of reaching the connector.
  3. If seen in tests, build a minimal config: &types.DataSourceConfig{Credentials: map[string]interface{}{"feed_urls": "https://example.com/feed"}}.
  4. Add an upstream nil-check/guard so the connector is never invoked without a config.

Example fix

// before
conn.Validate(ctx, nil)
// after
cfg := &types.DataSourceConfig{Credentials: map[string]interface{}{"feed_urls": "https://example.com/rss"}}
if cfg == nil { return errors.New("missing datasource config") }
conn.Validate(ctx, cfg)
Defensive patterns

Strategy: validation

Validate before calling

if config == nil {
    return fmt.Errorf("datasource config is missing; cannot validate RSS source")
}
if len(config.Credentials) == 0 && len(config.Settings) == 0 {
    return fmt.Errorf("datasource config has no credentials or settings")
}

Type guard

func hasConfig(c *types.DataSourceConfig) bool { return c != nil }

Try / catch

cfg, err := parseConfig(config)
if errors.Is(err, datasource.ErrInvalidConfig) {
    // surface as user-facing "source not configured"
    return err
}

Prevention

When it happens

Trigger: Any call to Validate, ListResources, or walk on the RSS connector where the *types.DataSourceConfig argument is nil, e.g. an upstream service built the config object conditionally and skipped it, or a test harness invoked the connector without a config.

Common situations: A datasource record was deleted or not yet created but the UI still triggered a validation; a migration or restore produced sources with an empty/missing config blob that decoded to nil; unit tests calling parseConfig directly without constructing a DataSourceConfig.

Related errors


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