Repository: sympy/sympy

Issue:
Bug in Quantity._collect_factor_and_dimension
This should give an error, but it fails in the wrong place:
```python
from sympy import S, exp
from sympy.physics.units import length, mass, Quantity

u = Quantity("u")
v = Quantity("v")
u.set_dimension(length)
v.set_dimension(mass)
Quantity._collect_factor_and_dimension(1 - exp(u/v))
```
returns:

> AttributeError: 'Mul' object has no attribute 'name'
This is because the code expects a quantity but encounters an expression in the exponent.

Discussion:

Patch:
diff --git a/sympy/physics/units/quantities.py b/sympy/physics/units/quantities.py
index 47bb4b6ede..ac91350ebc 100644
--- a/sympy/physics/units/quantities.py
+++ b/sympy/physics/units/quantities.py
@@ -207,7 +207,7 @@ def _collect_factor_and_dimension(expr):
                     raise ValueError(
                         'Dimension of "{0}" is {1}, '
                         'but it should be {2}'.format(
-                            addend, addend_dim.name, dim.name))
+                            addend, addend_dim, dim))
                 factor += addend_factor
             return factor, dim
         elif isinstance(expr, Derivative):


Test patch:
diff --git a/sympy/physics/units/tests/test_quantities.py b/sympy/physics/units/tests/test_quantities.py
index 553e70c40b..cf728d59c8 100644
--- a/sympy/physics/units/tests/test_quantities.py
+++ b/sympy/physics/units/tests/test_quantities.py
@@ -184,6 +184,7 @@ def check_unit_consistency(expr):
     raises(ValueError, lambda: check_unit_consistency(u - w))
     raises(ValueError, lambda: check_unit_consistency(u + 1))
     raises(ValueError, lambda: check_unit_consistency(u - 1))
+    raises(ValueError, lambda: check_unit_consistency(1 - exp(u / w)))
 
 
 def test_mul_div():