Consider the vector field $$F(x,y) = \left(-\frac{y}{x^2+y^2}, \frac{x}{x^2+y^2}\right).$$ This field is not conservative, since its integral on any circumference of radius $R$ and center at the origin is not zero.
However, if we consider $F$ only for $y > 0$, for example, then it becomes conservative, since it is defined in an open and simply connected region of the plane. However, which function is the potencial? A candidate would be $$f(x,y) = \arctan\left(\frac{y}{x}\right),$$ but it is not defined for $x = 0$, so we cannot say that $\nabla f = F$ for all $(x,y)$ such that $y > 0$, or can we? Am I missing something here?
Consider the function $f: \Bbb{R} \times (0,\infty) \to \Bbb{R}$ defined by \begin{align} f(x,y) &:= \frac{\pi}{2} - \arctan\left(\frac{x}{y}\right) \end{align} Then, a simple calculation shows that $\nabla f = F$. Geometrically, the term $\arctan\left(\frac{x}{y}\right)$ measures the angle counter-clockwise starting from the positive $y$-axis (so that if $x<0$ the angle is positive, and if $x>0$ the angle is negative), and the $\pi/2$ is simply the angle to the positive $y$-axis. Thus, $f$ is indeed the angle measured counter-clockwise starting from the positive $x$-axis.
This is the desired extension of $\arctan(y/x)$ to the case $y>0$.
Note that in general, given any half-line $H$ (i.e for a fixed $\alpha \in \Bbb{R}$, a set of the form $\{(r\cos \alpha, r \sin \alpha)| \, \, r \geq 0\}\subset \Bbb{R}^2$), you can always define an angle function on the complement $H^c:= \Bbb{R}^2\setminus H$ such that the angle function is smooth on $H^c$, and such that its gradient on $H^c$ is exactly the vector field $F$.