The ending should fit the overall point of the story. The characters shouldn't necessarily just get a happy ending because YAY.
But surprise endings are actually overwhelmingly less engaging than endings where you already know roughly what's going to happen, or at least what
might
happen.
To use an overly simplified example, compare these two scenes:
*John and James are sitting at a table in a restaurant*
John: So, did you bring it?
James: Yes, it's right here.
*John opens the box*
John: Wow, Marissa will love this necklace!
*the table explodes and they both die*
*John and James are sitting at a table in a restaurant*
*there is a bomb under the table*
John: So, did you bring it?
James: Yes, it's right here.
*the timer on the bomb is shown, with four seconds left*
*John opens the box*
John: Wow, Marissa will love this necklace!
*the table explodes and they both die*
There's a difference between canon and not-stupid.