moodle/moodle · error · PhpOffice\PhpSpreadsheet\Calculation\Exception

Prefix not allowed for UoM

Error message

Prefix not allowed for UoM

What it means

CONVERTUOM's helper getUOMDetails() failed to resolve the unit-of-measure string: it was not found in the conversion table, and after stripping a leading character as a metric prefix, the remaining unit either is not a known unit or the prefix is not a valid metric multiplier for that unit's group. Since prefixes only apply to units that permit them, this input is rejected with an Exception (surfaced as an Excel error) — i.e. a malformed or unsupported 'from'/'to' UoM argument.

Solutions

  1. Use a recognized unit code from PhpSpreadsheet's CONVERT unit tables
  2. Only attach metric prefixes (k, M, G, m, u, n, ...) to units whose group allows prefixes (e.g. gram, meter)
  3. Check for typos or stray characters in the UoM string (case-sensitive codes)
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php:589 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of moodle/moodle@48ea8c3322 (2026-09-14). Data as JSON: /api/errors/4fe047643165dd59. Report an issue: GitHub.

Appendix: source

Thrown at public/lib/phpspreadsheet/phpspreadsheet/src/PhpSpreadsheet/Calculation/Engineering/ConvertUOM.php:589

        return ($baseValue * self::$unitConversions[$fromCategory][$toUOM]) / $toMultiplier;
    }

    /** @return array{0: string, 1: string, 2: float} */
    private static function getUOMDetails(string $uom): array
    {
        if (isset(self::$conversionUnits[$uom])) {
            $unitCategory = self::$conversionUnits[$uom]['Group'];

            return [$uom, $unitCategory, 1.0];
        }

        // Check 1-character standard metric multiplier prefixes
        $multiplierType = substr($uom, 0, 1);
        $uom = substr($uom, 1);
        if (isset(self::$conversionUnits[$uom], self::$conversionMultipliers[$multiplierType])) {
            if (self::$conversionUnits[$uom]['AllowPrefix'] === false) {
                throw new Exception('Prefix not allowed for UoM');
            }
            $unitCategory = self::$conversionUnits[$uom]['Group'];

            return [$uom, $unitCategory, self::$conversionMultipliers[$multiplierType]['multiplier']];
        }

        $multiplierType .= substr($uom, 0, 1);
        $uom = substr($uom, 1);

        // Check 2-character standard metric multiplier prefixes
        if (isset(self::$conversionUnits[$uom], self::$conversionMultipliers[$multiplierType])) {
            if (self::$conversionUnits[$uom]['AllowPrefix'] === false) {
                throw new Exception('Prefix not allowed for UoM');
            }
            $unitCategory = self::$conversionUnits[$uom]['Group'];

            return [$uom, $unitCategory, self::$conversionMultipliers[$multiplierType]['multiplier']];
        }

View on GitHub (pinned to 48ea8c3322)