As a new PhD supervisor, how should I deal with taking a student to a wrong direction? I am a postdoc who was supposed to co-supervise a PhD student along with another academic who invited me for that. However, I ended up fully supervising the student after the supervisor became too busy to attend meetings. Eventually, I also ended up defining a problem for the student, which, after 2 months of work, we discovered it is invalid. How should I deal with this situation? I feel that it's my fault and feel bad for the student. The student is in his first year, and this is his first research problem.

Any ideas on this from experienced supervisors over here? Thank you.

Edit: Thank you, everyone, for contributing your answers and comments. For those of you talking about failure/recovery/publishing what's in hand, I would clarify that the discovered issue is in the problem formulation, where the solution would involve inverting a rank-deficient matrix and differentiating a non-differentiable function. Thus, a mathematical solution is not defined. Therefore, the formulation is invalid. This wasn't foreseeable at the beginning, and only when the student made some deviations, it was possible to reach this conclusion. Now, in terms of publication and thesis content, the efforts exerted thus far don't mean anything.
On the grand scheme of things, what you just described is not the worst I've heard of. There are cases where a student spends years of their Ph. D. on a problem with nothing to show for in the end, for a variety of reasons. Sometimes even experienced advisors will, intentionally or unintentionally, end up letting their students work on ideas that are terrible in hindsight. A couple of months wasted in the first year really is not a big deal (and there are certainly worse ways to waste one's time as a grad student). Besides just learning the lesson and moving on, here are a couple perspectives that I find helpful:


Defining the research question is not the sole responsibility of the advisor. It is true that the advisor sometimes has to act as a quality check for the students' work, but the point of PhD is to take responsibility for your own work. So the fact that the student just accepted the research question without asking whether it's valid or not (I assume) is partly the student's fault as well.
Try to salvage the effort spent as much as possible. Oftentimes it is possible to recast what you've done in light of a different research question, and you should consider whether that's possible in your case. I'd go so far as to say that one should always work on things that will be publishable even if your original hypothesis turns out to be wrong.