In Pinter's A Book of Abstract Algebra, the cancellation law is explained like this:
$ab=ac$
$a^{-1}ab=a^{-1}ac$
$eb=ec$
But then it goes on to say that
In general, we cannot cancel $a$ in the equation $ab=ca$. (Why not?)
At first I thought that it had to do with commutativity, but that can't be it because multiplication by inverses and by the identity is generally commutative right?
So if we apply $a^{-1}$ on from the left on the LHS, and from the right on the RHS, we get
$a^{-1}ab=caa^{-1}$
Then by the law of associativity
$(a^{-1}a)b=c(aa^{-1})$
Since an operation with inverses is commutative,
$eb=ce$
And since operations involving the identity are commutative,
$b=c$
So what's wrong with that?
Here's your mistake:
Once you multiply on the left (or the right) of a word (i.e., a string of elements) in an equation, you have to do the same on the other side of the equation, like so:
$$a^{-1}(ab)=\color{red}{a^{-1}}(ca).$$
For a counterexample to the cancellation candidate, consider the group given by the presentation $$\langle a,b,c\mid ab=ca \rangle;$$ that is, via Tietze transformations, the group given by $$\langle a,b,c\mid c=aba^{-1}\rangle;$$ i.e., the presentation $$\langle a,b\mid\varnothing \rangle,$$ which yields the free product $\Bbb Z\ast\Bbb Z$.