sipeed/picoclaw · error

teams_webhook: failed to build card

Error message

teams_webhook: failed to build card: %w

What it means

Returned by TeamsWebhookChannel.Send when buildAdaptiveCard fails to convert the outbound message (markdown tables, formatting) into an Adaptive Card. The %w wraps the underlying parse failure — most often a malformed markdown table produced by the model's output formatting.

Solutions

  1. Inspect the wrapped error to find which markdown construct (usually a table) failed to parse
  2. Regenerate or sanitize the message content so tables have header and separator rows
  3. Retry the send with plain text if rich card rendering keeps failing
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at pkg/channels/teams_webhook/teams_webhook.go:163 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/729e068cdf87a2e5. Report an issue: GitHub.

Appendix: source

Thrown at pkg/channels/teams_webhook/teams_webhook.go:163

	targetName := msg.ChatID
	if targetName == "" {
		targetName = "default"
	}

	target, ok := c.config.Webhooks[targetName]
	if !ok {
		// Log warning and fall back to default target
		logger.WarnCF("teams_webhook", "Unknown target, falling back to default", map[string]any{
			"requested": msg.ChatID,
			"using":     "default",
		})
		target = c.config.Webhooks["default"]
	}

	// Build an Adaptive Card for rich formatting
	card, err := c.buildAdaptiveCard(msg, target)
	if err != nil {
		return nil, fmt.Errorf("teams_webhook: failed to build card: %w", err)
	}

	// Create the message with the card
	teamsMsg, err := adaptivecard.NewMessageFromCard(card)
	if err != nil {
		return nil, fmt.Errorf("teams_webhook: failed to create message: %w", err)
	}

	// Send to Teams
	if err := c.client.SendWithContext(ctx, target.WebhookURL.String(), teamsMsg); err != nil {
		// Log without raw error to avoid leaking webhook URL (embedded in net/http errors)
		logger.ErrorCF("teams_webhook", "Failed to send message to Teams webhook", map[string]any{
			"target": msg.ChatID,
		})
		// Classify error based on status code extracted from error message.
		// The go-teams-notify library includes status in errors like "401 Unauthorized".
		// Use ClassifySendError for proper retry behavior (4xx = permanent, 5xx = temporary).
		classifiedErr := classifyTeamsError(err)

View on GitHub (pinned to 49183d7e8d)