I wrote this fast the first time, but will explain my reasoning as suggested by Joao Mendes in the comments.
Exams are unfair. They attempt to extract quantitative information about subjective things, but both students and teachers sometimes forget the subjective nature of this kind of assessment. A teacher will often consider a student weak because he/she didn't do well in an exam, and worse: The student will do the same with him/herself. Exams reflect so poorly the acquisition of knowledge that their results often don't even correlate with the ability of employing what they were supposed to measure.
I can give you an example in my field. Suppose student A did exceedingly well in a calculus exam such as the ones I used to take in my undergrad courses, where you were supposed to differentiate some artificially complicated function in order to assess if you had understood the chain rule. Student B did poorly in this exam, getting virtually all signs wrong, and failed it. Then, while working on a physics problem, student A was completely unable to even figure out what to differentiate, but student B noticed the secant approached the tangent and drew a picture that allowed you to write an expression. This expression could, then, be differentiated. Neither student could solve the problem alone, but A could use the expression from B and arrive at an answer.
The process above describes a collaborative aspect of knowledge that is essentially impossible to assess by an exam (although people do try sometimes). In the end, this is much closer to how knowledge works in the real world. We are not alone, and we have the right to not know. We also have the right to study and not learn. It is fine. In fact, in my personal experience, I have found out that student B in the example above it much more valuable than student A, since any computer can differentiate, but no computer can interpret (yet). In language, the teacher must ensure every student is reserved the right of finding it difficult. Not everyone is good with languages. You cannot blame the French for being unable to speak a proper "r" in English, given that their own language doesn't have that sound. The teacher has no context over a student's background, motivation, personal problems. Even in the subject you are yourself teaching, what you get when you talk to students about their difficulties is only an approximation, because they themselves are often unable to pinpoint a cause for their poor performance. It's not their fault: it is extremely subjective.
There are students who fail exams, and there are exams that fail students. I prefer to always work with the possibility of my exam being unfit for what I wanted, especially when I see that a student is working hard. If they do work hard and have a poor grade, I personally tell them that that grade means nothing. That I don't really know what I'm doing when providing a grade, because as for myself I don't feel that exams capture much. Unfortunately, the alternative assessments demand too much time and effort, and we end up stuck with our poor, medieval methods. In the end, my nightmare is not missing out a bad student and giving them a good grade, but to block a good student from reaching his/her full potential. The former will be corrected by life itself, but the latter is so destructive I cannot allow myself to be the cause.
Thus, here is my suggestion:
I am sorry about your test result. Unfortunately, it is not always
easy to understand why we failed an exam. Sometimes we study a lot and
fail, but the opposite can also happen. In the end, exams are
not perfect. The most important things you have to ask are: do you
think you are learning Spanish? Do you feel like you are studying and
gradually improving? Do you feel motivated in this course?
If the answers are all positive, then we must understand why the exam
didn't capture them. Feel free to drop by my office etc etc...