{"record":{"id":"d6e4abc3c639331c","repo":"TheAlgorithms/Python","slug":"area-cannot-be-negative","errorCode":null,"errorMessage":"Area cannot be negative","messagePattern":"Area cannot be negative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/shear_stress.py","lineNumber":38,"sourceCode":"    2. Tangential Force\n    3. Cross-sectional Area\n    This is calculated from the other two provided values\n    Examples -\n    >>> shear_stress(stress=25, tangential_force=100, area=0)\n    ('area', 4.0)\n    >>> shear_stress(stress=0, tangential_force=1600, area=200)\n    ('stress', 8.0)\n    >>> shear_stress(stress=1000, tangential_force=0, area=1200)\n    ('tangential_force', 1200000)\n    \"\"\"\n    if (stress, tangential_force, area).count(0) != 1:\n        raise ValueError(\"You cannot supply more or less than 2 values\")\n    elif stress < 0:\n        raise ValueError(\"Stress cannot be negative\")\n    elif tangential_force < 0:\n        raise ValueError(\"Tangential Force cannot be negative\")\n    elif area < 0:\n        raise ValueError(\"Area cannot be negative\")\n    elif stress == 0:\n        return (\n            \"stress\",\n            tangential_force / area,\n        )\n    elif tangential_force == 0:\n        return (\n            \"tangential_force\",\n            stress * area,\n        )\n    else:\n        return (\n            \"area\",\n            tangential_force / stress,\n        )\n\n\nif __name__ == \"__main__\":","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/shear_stress.py#L20-L56","documentation":"Raised by physics/shear_stress.py:shear_stress when the caller passes a negative value for the area argument. shear_stress solves for one of stress, tangential_force, or area from the other two, and a negative area is physically meaningless (it would flip the sign of the computed stress), so the function refuses it before doing any arithmetic. It is one of three per-argument sign checks that run after the 'exactly two of three inputs must be non-zero' check.","triggerScenarios":"Calling shear_stress with area < 0, e.g. shear_stress(stress=1000, tangential_force=500, area=-200) or shear_stress(stress=0, tangential_force=1600, area=-200). Note the check fires only when exactly one of the three arguments is 0; otherwise the 'more or less than 2 values' ValueError fires first.","commonSituations":"Swapping argument order so a force value lands in the area slot; computing area as a difference (a-b) that goes negative for degenerate geometry; porting unit conversions (cm^2 to m^2) that introduce a sign error; passing sentinel values like -1 for 'unknown'.","solutions":["Pass a non-negative area; area must be > 0 when it is the unknown being solved for.","Check argument order against the signature shear_stress(stress, tangential_force, area) - magnitudes differ by orders of magnitude so a swap is usually visible.","If area is derived, clamp or validate the geometry inputs so the computed area cannot go negative.","Wrap the call in try/except ValueError if negative intermediates are possible in your pipeline and you want to reject the sample explicitly."],"exampleFix":"# before\nshear_stress(stress=0, tangential_force=1600, area=-200)\n\n# after\nshear_stress(stress=0, tangential_force=1600, area=200)","handlingStrategy":"validation","validationCode":"if area < 0:\n    raise ValueError(f'area must be >= 0, got {area}')\nresult = shear_stress(stress=s, tangential_force=f, area=area)","typeGuard":"def is_valid_shear_input(stress, tangential_force, area) -> bool:\n    return (stress, tangential_force, area).count(0) == 1 and min(stress, tangential_force, area) >= 0","tryCatchPattern":"try:\n    shear_stress(stress=s, tangential_force=f, area=a)\nexcept ValueError as e:\n    if 'Area' in str(e):\n        # handle bad area specifically\n        ...","preventionTips":["Use keyword arguments (stress=, tangential_force=, area=) to avoid positional swaps.","Validate derived areas (differences of lengths) for sign before calling.","Remember exactly one of the three inputs must be 0 to select the unknown."],"tags":["physics","validation","valueerror","shear-stress"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}