# Trigonometric equation in two ways gives different answer

I have been given the equation $\sin^2 x+ \cos x +1 = 0.$ I tried to solve it in two ways. First, $1 - \cos^2(x) + \cos(x) + 1 = 0,$ $\cos^2(x) - \cos(x) - 2 = 0,$ $\cos x=2$ or $\cos x=-1$ thus $x=\pi+n2\pi$ for all $n\in \mathbb{Z}.$

Second approach. Let $\tan \frac{x}{2}=t.$ Then $\sin x=\frac{2t}{1+t^2}$ and $\cos x=\frac{1-t^2}{1+t^2}.$ Thus the equation is $$\left (\frac{2t}{1+t^2}\right )^2+\frac{1-t^2}{1+t^2}+1=0.$$ Therefore $$4t^2+(1-t^2)(1+t^2)+(1+t^2)^2=0.$$ But $$4t^2+(1-t^2)(1+t^2)+(1+t^2)^2=4t^2+1-t^4+1+2t^2+t^4=6t^2+2>0.$$ and there is no solutions.

What is my mistake in the second reasoning?

You are defining $t = \tan\cfrac{x}{2} = \cfrac{\sin \cfrac{x}2}{\cos \cfrac{x}2}$, which disqualifies any root for which $\cos \cfrac{x}2 = 0$.
What happens when $x = \pi + 2\pi n$?
The second method is perfectly fine, but you have to take care of undefined values of $t$ separately.