The question is to solve this $DE$:
$$(E):y'-\frac{1}{x}y^2+(2+\frac{1}{x})y=x+2$$
As a hint, the particular solution was given, $u(x)=x$ is a solution to this $D.E$.
When trying to solve the homogeneous $D.E$
$$(H): y'-\frac{1}{x}y^2+(2+\frac{1}{x})y=0$$ $$(H): \frac{y'}{y^2}+(2+\frac{1}{x})\frac{1}{y}=\frac{1}{x}$$
by doing the known substitution $u=y^{-1} \implies u'=-y^{-2}y'$ we get to a first order $ODE$ :
$(E_1): v'-(2+\frac{1}{x})v=-\frac{1}{x}$
which then we solve the homogenous equation: $v'-(2+\frac{1}{x})v=0 $
We find $v_h(x)=Ce^{2x}x \implies v'_h(x)=C'e^{2x}x+C(2e^{2x}x+e^{2x})$
. By the method of constant variation, we find the $v_p$, but this is where i'm having trouble, After substituing in $(E_1)$, I get:
$C'e^{2x}x+C(2e^{2x}x+e^{2x})+(2+\frac{1}{x}) Ce^{2x}x=-\frac{1}{x} \implies C'=-\frac{e^{-2x}}{x^2}$, but integrating this is not easy (i think), after plugging it into online integral calculators, It seems that it's not expressible in elementary functions.
So maybe the way i'm approaching this is wrong from the start? Any help is appreciated! thanks.
Normally you are supposed to use $y=z+x$ as a susbstitution
Then you get the Bernouilli's equation
$$z'+\frac zx=\frac {z^2}{x}$$ $$xz'+ z=\frac {x^2z^2}{x^2}$$ $$(xz)'=\frac {(xz)^2}{x^2}$$ $$\int \frac {dxz}{(xz)^2}=\int \frac {dx}{x^2}$$ $$z(x)=\frac {1}{Kx+1}$$ $$\boxed{y(x)=x+\frac {1}{Kx+1}}$$
I don't think you made a mistake with the variation of constant I didn't find any mistake. ..Sometimes it happens that the integral can't be evaluated with elementary functions.
Edit
Claude's answer is the same you end with the same solution whether you start with $y_p=x$ or $y_p=x+1$...
$$y=x+1-\frac x{x+c_1}$$ $$y=x+\frac {x+c_1}{x+c_1}-\frac x{x+c_1}$$ $$y=x+\frac {x+c_1-x}{x+c_1}$$ $$y=x+\frac {c_1}{x+c_1}$$ $$y=x+\frac {1}{x/c_1+1}$$ $$y=x+\frac {1}{Kx+1}$$