classifyImageCapError function

ImageCapRefusal? classifyImageCapError(
  1. String? errorMessage
)

Whether errorMessage is an image-count cap refusal, and — when it is — the (modelId, learnedCap) parsed from it (issue #1750).

Returns null for everything else (near-misses like maximum allowed for model X is 10 WITHOUT too many images, auth 400s, rate limits, context overflows). An unparseable cap digit cannot match (the group is \d+); a matched-but-degenerate cap (is 0) still classifies — the refusal IS the family — and the caller's degenerate-cap guard skips the re-send (edge E3).

Implementation

ImageCapRefusal? classifyImageCapError(String? errorMessage) {
  if (errorMessage == null) return null;
  for (final pattern in _imageCapPatterns) {
    final match = pattern.firstMatch(errorMessage);
    if (match == null) continue;
    return ImageCapRefusal(
      modelId: match.group(1)!,
      learnedCap: int.parse(match.group(2)!),
    );
  }
  return null;
}