Mistake with using residue theory for calculating $\int_{-\infty}^{\infty}\frac{\sin(x)}{x}dx$

The problem here is actually quite subtle, you've used the residue theorem correctly to evaluate the entire contour integral, and you've correctly identified that the integral over $C_1$ goes to $0$ as $R \to \infty$. This gave you a correct value for the imaginary part of the integral (for $\epsilon > 0$) $$\operatorname{Im}\left(\int_{-\infty}^{\infty}\frac{e^{iz}}{z - i \epsilon}d z\right) = 2\pi e^{-\epsilon}$$ which you can confirm here.

But, the problem happens when taking the limit as $\epsilon \to 0$, in that there's no guarantee that

$$\lim_{\epsilon \to 0} \int_{-\infty}^{\infty}\frac{e^{iz}}{z - i \epsilon}d z = \int_{-\infty}^{\infty} \lim_{\epsilon \to 0} \frac{e^{iz}}{z - i \epsilon}d z$$ This is where the solution breaks down, and your discrepancy here is a nice demonstration of how swapping the order of the limits needs more justification - in particular remember that the integral is defined as a limiting process, so some fairly strong continuity arguments would be required to show the left and right above would be equal. Of course in physics, you're used to assuming everything is as continuous as you'd like! In this particular case, it turns out $\int_{-\infty}^{\infty}\frac{e^{iz}}{z - i \epsilon}d z$ isn't continuous at $\epsilon=0$, so here's where your mistake is.


The problem is that in this case,

$$\int_{-\infty}^\infty\lim_{\varepsilon\rightarrow0}\frac{\sin x}{x-i\varepsilon}dx\ne\lim_{\varepsilon\rightarrow0}\int_{-\infty}^\infty\frac{\sin x}{x-i\varepsilon}dx.$$

The left-hand side is what you want, but the right-hand side is what you actually calculated. Really, what you found was the limit as $\varepsilon\rightarrow0^+$. If you had instead had $\varepsilon$ approach $0$ from below, you would have gotten $0$ as your answer. The limit on the left-hand side works out the same whether $\varepsilon$ approaches $0$ from the right or the left, so the fact that we get two different answers for the right-hand side immediately tells us something is wrong.

While this isn't rigorous, you'll note that the correct answer is halfway between the $2\pi$ you found for $\varepsilon\rightarrow0^+$ and the $0$ you get for $\varepsilon\rightarrow0^-$.