{"record":{"id":"6e9ea1e7d1e2ea55","repo":"TheAlgorithms/Python","slug":"invalid-from-type-value-from-type-r-supporte-6e9ea1","errorCode":null,"errorMessage":"Invalid 'from_type' value: {from_type!r}  Supported values are:\n{', '.join(METRIC_CONVERSION)}","messagePattern":"Invalid 'from_type' value: (.+?)  Supported values are:\n(.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/volume_conversions.py","lineNumber":64,"sourceCode":"    0.264172\r\n    >>> volume_conversion(1, \"kilolitre\", \"cubic meter\")\r\n    1\r\n    >>> volume_conversion(3, \"gallon\", \"cubic yard\")\r\n    0.017814279\r\n    >>> volume_conversion(2, \"cubic yard\", \"litre\")\r\n    1529.1\r\n    >>> volume_conversion(4, \"cubic foot\", \"cup\")\r\n    473.396\r\n    >>> volume_conversion(1, \"cup\", \"kilolitre\")\r\n    0.000236588\r\n    >>> volume_conversion(4, \"wrongUnit\", \"litre\")\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: Invalid 'from_type' value: 'wrongUnit'  Supported values are:\r\n    cubic meter, litre, kilolitre, gallon, cubic yard, cubic foot, cup\r\n    \"\"\"\r\n    if from_type not in METRIC_CONVERSION:\r\n        raise ValueError(\r\n            f\"Invalid 'from_type' value: {from_type!r}  Supported values are:\\n\"\r\n            + \", \".join(METRIC_CONVERSION)\r\n        )\r\n    if to_type not in METRIC_CONVERSION:\r\n        raise ValueError(\r\n            f\"Invalid 'to_type' value: {to_type!r}.  Supported values are:\\n\"\r\n            + \", \".join(METRIC_CONVERSION)\r\n        )\r\n    return (\r\n        value\r\n        * METRIC_CONVERSION[from_type].from_factor\r\n        * METRIC_CONVERSION[to_type].to_factor\r\n    )\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    import doctest\r\n\r","sourceCodeStart":46,"sourceCodeEnd":82,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/volume_conversions.py#L46-L82","documentation":"Raised by volume_conversion() in conversions/volume_conversions.py when from_type is not a key in METRIC_CONVERSION. Supported units (exact strings): cubic meter, litre, kilolitre, gallon, cubic yard, cubic foot, cup. The message embeds the full list at runtime.","triggerScenarios":"Calling volume_conversion(4, 'wrongUnit', 'litre'), using 'liter' (US spelling) instead of 'litre', or 'millilitre'/'ml' which the chart does not contain.","commonSituations":"US-locale data using 'liter'/'gallons' (plural) tokens; metric sub-units (ml, cm3, teaspoon) not covered by this seven-unit chart; display labels passed unmodified.","solutions":["Use one of: cubic meter, litre, kilolitre, gallon, cubic yard, cubic foot, cup (singular, British spelling for litre).","Normalize aliases first: {'liter': 'litre', 'liters': 'litre', 'ml': 'litre' with a 0.001 factor, 'gallons': 'gallon'}.","For ml/cm3, convert via litre yourself (1 ml = 0.001 litre, 1 cm3 = 1 ml) before or after calling."],"exampleFix":"# before\nvolume_conversion(1, 'liter', 'cup')  # ValueError: Invalid 'from_type' value: 'liter'\n\n# after\nALIASES = {'liter': 'litre', 'liters': 'litre', 'gallons': 'gallon', 'cubic meters': 'cubic meter'}\nvolume_conversion(1, ALIASES['liter'], 'cup')","handlingStrategy":"validation","validationCode":"from conversions.volume_conversions import METRIC_CONVERSION\n\nfrom_type = ALIASES.get(from_type.lower(), from_type)\nif from_type not in METRIC_CONVERSION:\n    raise ValueError(f'unsupported volume unit {from_type!r}')\nvolume_conversion(value, from_type, to_type)","typeGuard":"from conversions.volume_conversions import METRIC_CONVERSION\n\ndef is_volume_unit(u: object) -> bool:\n    return isinstance(u, str) and u in METRIC_CONVERSION","tryCatchPattern":"try:\n    volume_conversion(v, f, t)\nexcept ValueError as e:\n    if 'from_type' in str(e):\n        f = {'liter': 'litre', 'liters': 'litre'}.get(f.lower(), f)\n        result = volume_conversion(v, f, t)\n    else:\n        raise","preventionTips":["British spelling 'litre' and singular forms are required","Map ml to litre with a 0.001 factor yourself","Drive unit pickers from METRIC_CONVERSION keys"],"tags":["python","validation","units","volume","conversion"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}