Tencent/WeKnora · error

unable to parse date: %s

Error message

unable to parse date: %s

What it means

Returned by parseBaiduDate when the date string from a Baidu result matches none of the expected formats (baiduDateRe finds no components). The error is logged/tolerated by doSearch — the result is kept without a PublishedAt timestamp.

Source

Thrown at internal/infrastructure/web_search/baidu.go:175

		if includeDate && ref.Date != "" {
			if t, err := parseBaiduDate(ref.Date); err == nil {
				result.PublishedAt = &t
			}
		}

		results = append(results, result)
	}
	return results, nil
}

var baiduDateRe = regexp.MustCompile(`^(\d{4})-(\d{1,2})-(\d{1,2})(?:\s+(\d{1,2}):(\d{2})(?::(\d{2}))?)?`)

// parseBaiduDate extracts date components via regex, handling variable formats
// like "2025-4-24", "2025-04-27 18:02:00", "2025-05-20 11:58" uniformly.
func parseBaiduDate(dateStr string) (time.Time, error) {
	m := baiduDateRe.FindStringSubmatch(dateStr)
	if m == nil {
		return time.Time{}, fmt.Errorf("unable to parse date: %s", dateStr)
	}
	// Pad to "YYYY-MM-DD HH:MM:SS" and parse once
	normalized := fmt.Sprintf("%s-%02s-%02s %02s:%02s:%02s",
		m[1], m[2], m[3],
		defaultStr(m[4], "00"), defaultStr(m[5], "00"), defaultStr(m[6], "00"))
	return time.Parse("2006-01-02 15:04:05", normalized)
}

func defaultStr(s, fallback string) string {
	if s == "" {
		return fallback
	}
	return s
}

// Baidu documents the query length limit as 72 chars, counting CJK/full-width
// runes as 2. Use a conservative width model so mixed-language input stays
// under the API limit.

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Inspect the unexpected date format and extend baiduDateRe if it is a new valid variant
  2. Accept results without PublishedAt — the search pipeline already handles a missing date
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at internal/infrastructure/web_search/baidu.go:175 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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