{"record":{"id":"2ce3d8a78e41850c","repo":"TheAlgorithms/Python","slug":"stress-cannot-be-negative","errorCode":null,"errorMessage":"Stress cannot be negative","messagePattern":"Stress cannot be negative","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"physics/shear_stress.py","lineNumber":34,"sourceCode":") -> tuple[str, float]:\n    \"\"\"\n    This function can calculate any one of the three -\n    1. Shear Stress\n    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,","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/physics/shear_stress.py#L16-L52","documentation":"Raised by shear_stress() when the stress argument is negative (and exactly one argument is 0). Stress in this model is a non-negative magnitude, so a negative value is rejected before the solve branches. Note the elif chain order: a negative stress masks negative force/area errors.","triggerScenarios":"shear_stress(stress=-25, tangential_force=100, area=0) — negative stress with area as the unknown; signed stress from a FEA solver where compression is negative fed directly.","commonSituations":"FEA continuum-mechanics sign conventions (compressive stress negative) not converted to magnitudes; CSV sign errors; reusing values from a Mohr's-circle computation that returned signed principal stresses.","solutions":["Pass the magnitude: shear_stress(stress=abs(sigma), ...)","Convert from your FEA convention first, e.g. take abs() of signed principal stress","Sanitize imported data by rejecting or abs()-ing negative stress values deliberately, with a log line"],"exampleFix":"# before\nshear_stress(stress=-25, tangential_force=100, area=0)\n# ValueError: Stress cannot be negative\n\n# after\nshear_stress(stress=abs(-25), tangential_force=100, area=0)","handlingStrategy":"validation","validationCode":"if stress < 0:\n    stress = abs(stress)  # convert FEA signed stress to magnitude\nshear_stress(stress, tangential_force, area)","typeGuard":null,"tryCatchPattern":"try:\n    shear_stress(stress, tangential_force, area)\nexcept ValueError as e:\n    if \"Stress cannot be negative\" in str(e):\n        shear_stress(abs(stress), tangential_force, area)\n    else:\n        raise","preventionTips":["Convert signed FEA/continuum stresses (compression negative) to magnitudes first","Stress is checked first in the elif chain — a negative stress masks later sign errors"],"tags":["physics","validation","negative-value","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}