we-promise/sure · error · Family::AutoCategorizer::Error

Failed to auto-categorize transactions: #{result.error.messa

Error message

Failed to auto-categorize transactions: #{result.error.message}

What it means

Raised when llm_provider.auto_categorize(transactions:, user_categories:, family:) returns an unsuccessful Result; the message embeds result.error.message from the provider client. Causes live in the LLM provider call itself: auth failures, rate limits, timeouts, or responses that fail the provider's parsing into Result(success?: false).

Source

Thrown at app/models/family/auto_categorizer.rb:33

    else
      Rails.logger.info("Auto-categorizing #{scope.count} transactions for family #{family.id}")
    end

    categories_input = user_categories_input

    if categories_input.empty?
      Rails.logger.error("Cannot auto-categorize transactions for family #{family.id}: no categories available")
      return 0
    end

    result = llm_provider.auto_categorize(
      transactions: transactions_input,
      user_categories: categories_input,
      family: family
    )

    unless result.success?
      raise Error, "Failed to auto-categorize transactions: #{result.error.message}"
    end

    modified_count = 0
    scope.each do |transaction|
      auto_categorization = result.data.find { |c| c.transaction_id == transaction.id }

      category_id = categories_input.find { |c| c[:name] == auto_categorization&.category_name }&.dig(:id)

      if category_id.present?
        was_modified = transaction.enrich_attribute(
          :category_id,
          category_id,
          source: "ai"
        )
        transaction.lock_attr!(:category_id)
        # enrich_attribute returns true if the transaction was actually modified
        modified_count += 1 if was_modified
      end

View on GitHub (pinned to e69894adb9)

Solutions

  1. Read the embedded result.error.message — it is the provider's own error text and distinguishes auth vs rate limit vs parsing
  2. Retry after the rate-limit window or reduce the transaction_ids batch size
  3. Verify provider credentials (ENV) are still valid; check the provider status page
  4. Rescue Family::AutoCategorizer::Error at the job layer and mark the job failed with the message instead of crashing the queue

Example fix

// before
Family::AutoCategorizer.new(family, transaction_ids: ids).auto_categorize

// after
begin
  Family::AutoCategorizer.new(family, transaction_ids: ids).auto_categorize
rescue Family::AutoCategorizer::Error => e
  Rails.logger.error("Auto-categorize failed: #{e.message}")
  raise # let the job retry with backoff
end
Defensive patterns

Strategy: try-catch

Try / catch

rescue Family::AutoCategorizer::Error => e and read the embedded provider message: retry with backoff for rate-limit/network causes, fail fast for auth causes; never swallow silently since the batch was already charged/queued

Prevention

When it happens

Trigger: The provider HTTP request fails or returns an error payload while categorizing a batch — expired/revoked API key, 429 rate limit, network timeout, or a malformed model response that cannot be parsed.

Common situations: Large batches hitting requests-per-minute or token limits; rotated API keys; provider incidents; oversized transaction payloads exceeding model context.

Related errors


AI-assisted analysis of we-promise/sure@e69894adb9 (2026-08-21). Data as JSON: /api/errors/948b51f9bab814b4. Report an issue: GitHub.