phacility/phabricator · error · Exception

Maximum allowed amount is %s.

Error message

Maximum allowed amount is %s.

What it means

Thrown by PhortuneCurrency::assertInRange($minimum, $maximum) when the object's value (integer cents) exceeds the parsed $maximum. Bounds are inclusive: the check is $max->value < $this->value, so a value exactly equal to the maximum passes. The message shows the maximum formatted for display (e.g. '$500.00 USD'), ready to show to an end user.

Source

Thrown at src/applications/phortune/currency/PhortuneCurrency.php:228

            $min->formatForDisplay(),
            $max->formatForDisplay()));
      }
    }

    if ($minimum !== null) {
      $min = self::newFromString($minimum);
      if ($min->value > $this->value) {
        throw new Exception(
          pht(
            'Minimum allowed amount is %s.',
            $min->formatForDisplay()));
      }
    }

    if ($maximum !== null) {
      $max = self::newFromString($maximum);
      if ($max->value < $this->value) {
        throw new Exception(
          pht(
            'Maximum allowed amount is %s.',
            $max->formatForDisplay()));
      }
    }

    return $this;
  }


}

View on GitHub (pinned to 5720a38cfe)

Solutions

  1. Lower the value being validated to or below the maximum shown in the message.
  2. Raise the configured maximum string if business rules changed — check where the bound is defined (config, product metadata, form field limit).
  3. Verify quantity math: unit price in range does not imply (unit * quantity) in range; assert on the computed total.
  4. Catch the Exception and render the message as a field-level validation error rather than letting it bubble as a 500.

Example fix

// before
$total->assertInRange('1.00 USD', '500.00 USD');

// after
try {
  $total->assertInRange('1.00 USD', '500.00 USD');
} catch (Exception $ex) {
  return $this->newDialog()
    ->setTitle(pht('Amount Too Large'))
    ->appendParagraph($ex->getMessage())
    ->addCancelButton($cart->getCheckoutURI());
}
Defensive patterns

Strategy: validation

Validate before calling

// Compare in cents BEFORE calling assertInRange.
function currency_within_maximum(PhortuneCurrency $amount, $maximum_string) {
  if ($maximum_string === null) {
    return true;
  }
  $max = PhortuneCurrency::newFromString($maximum_string);
  return $amount->getValue() <= $max->getValue();
}

if (!currency_within_maximum($total, $maximum)) {
  $field_error = pht(
    'Maximum allowed amount is %s.',
    PhortuneCurrency::newFromString($maximum)->formatForDisplay());
}

Try / catch

try {
  $total->assertInRange($minimum, $maximum);
} catch (Exception $ex) {
  // Bounds are inclusive; the message names the exact cap to show the user.
  return $this->newDialog()
    ->setTitle(pht('Amount Out of Range'))
    ->appendParagraph($ex->getMessage())
    ->addCancelButton($this->getApplicationURI());
}

Prevention

When it happens

Trigger: Calling PhortuneCurrency::newFromString('750.00 USD')->assertInRange('5.00 USD', '500.00 USD') — 75000 cents > 50000 cents throws. Typically hit when a product price, cart total, or one-time payment amount is set above a configured ceiling.

Common situations: Capping maximum purchase or top-up amounts to limit fraud exposure; subscription price ceilings in plan configuration; multiplying a unit price by a quantity and forgetting to re-check the total against the cap; changing a config ceiling after products were already priced above it.

Related errors


AI-assisted analysis of phacility/phabricator@5720a38cfe (2026-08-21). Data as JSON: /api/errors/6921090529294993. Report an issue: GitHub.