4. If there exists an obtuse angle $\alpha$, such that
$$
\sin \alpha-\sqrt{3} \cos \alpha=\log _{2}\left(x^{2}-x+2\right)
$$
holds, then the range of real number $x$ is ( ).
(A) $\{x \mid-1 \leqslant x<0$ or $1<x \leqslant 2\}$
(B) $\{x \mid-1<x<0$ or $1<x<2\}$
(C) $\{x \mid 0 \leqslant x \leqslant 1\}$
(D) $\{x \mid-1<x<2\}$
4.A.

Let $\frac{\pi}{2}<\alpha<\pi$. Then
$$
\sin \alpha-\sqrt{3} \cos \alpha=2 \sin \left(\alpha-\frac{\pi}{3}\right) \in(1,2] \text {. }
$$

Therefore, $1<\log _{2}\left(x^{2}+x+2\right) \leqslant 2$
Thus $2<x^{2}-x+2 \leqslant 4$.
Solving this, we get $-1 \leqslant x<0$ or $1<x \leqslant 2$.