I am trying to compute the line integral $$\int_{|z|=1}\frac{z^2+2}{z(z-3)}dz$$ where the circumference $\{|z|=1\}$ is positively orientated. I have used two different methods and I have obtained two different results, so I hope someone can point my mistake out.
First method
$f(z)=\frac{z^2+2}{z(z-3)}$ is not holomorphic if $z=0$ or if $z=3$. I define $\Omega=\{z\in \mathbb{C}:\frac{1}{2}<|z|<2\}$, which is simply connected open set, and $|z|=1\subset \Omega$. As $f$ is holomorphic in $\Omega$ and $|z|=1$ is a closed path in $\Omega$, then by Cauchy's integral theorem: $$\int_{|z|=1}f(z)dz=0$$
Second method
$g(z)=\frac{z^2+2}{z-3}$ is holomorphic in $\Omega'=\{z\in\mathbb{C}:Re(z)<3\}$ (simply connected open set). By Cauchy's integral formula (taking $a=0$): $$\int_{|z|=1}\frac{z^2+2}{z(z-3)}dz=\int_{|z|=1}\frac{g(z)}{z-0}dz=2\pi i\cdot g(0)=2\pi i \cdot \frac{2}{3}=\frac{4\pi i}{3}$$
As pointed out in the comments, the domain $\Omega$ is not simply connected (see https://en.wikipedia.org/wiki/Simply_connected_space), thus Cauchy's integral formula does not apply.
The second method is the right one, in its most general form it is called the residue theorem (https://en.wikipedia.org/wiki/Residue_theorem, one of the most important and powerful result in complex analysis!), and it says the following: $f(z)$ is a meromorphic function with only one simple pole (at $z=0$) enclosed by the loop $\gamma(t)=e^{it}, t \in [0,2\pi]$ we are integrating over, so we have \begin{equation}\int_{\gamma} f(z)dz = 2 \pi i \times \text{Res}(f,0)\times \text{Ind}_\gamma(0)=2\pi i \left(-\frac{2}{3}\right)1=-\frac{4\pi i}{3} \ , \end{equation} where the residue of $f$ at $z=0$ here is precisely $g(0)$ and the index of $\gamma$ with respect to $0$ (the « number of times $\gamma$ goes around $0$ ») is equal to 1.
*Here you can find methods for calculating residues: https://en.wikipedia.org/wiki/Residue_(complex_analysis)