There are a lot of other people out there who will unknowingly be very discouraging, to both children and adults, but their opinions have no bearing on our ability to learn. I remember being in music class in grade 1 and it was my absolute favorite class. Near the end of the year I was told that I wasn't very good at singing by my teacher. I never tried to sing again, but I learned later that I have good pitch and a decent voice. I am not really interested in singing now, but I might have learned a different set of skills if I didn't avoid it.
Is there a way that I could have been prepared so that being told by the person I looked up to for validation, that I was no good wouldn't make me stop trying to improve?
I don't know about that, but if there's a way to teach that, it would definitely be a good lesson. It would certainly be nice if teachers didn't do things like that, but even if you could guarantee they didn't, you won't stop the bullies or the critics or anyone other hater as you get older.
To the grandparent: I don't think getting upset is at all irrational.
Sigh, your statement reminds me of one time when I was in 6th grade geometry and was asked to complete this one proof. The problem was intended to get us to apply a concept we had been taught verbatim, but I couldn't remember it well and so I completed the proof a different way by extrapolating other basic concepts we had gone over into a method we had not been taught. I remember feeling very proud of myself when I finished, as I had created something which in my 12 year old eyes was a "novel proof". I ended up being given 0 points on the problem because I did not complete my proof using cookie cutter methods we had been taught (even though my proof was correct and it was not specified that I use a particular concept in the instructions).
I remember complaining to my teacher about how this was unfair and she kept saying something akin to "well you didn't do the problem the right way". The incident pretty much killed any interest I had in math, which wasn't rekindled until I stumbled upon machine learning recently in my 20s.